This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Declaring Arrays


Hi,

I am very confused about the way arrays are initialized under g++. (I am using Red Hat Linux 9)

	int size;
	cin >> size;
	int myarray[size];

According to what I had known earlier this should not be possible since the size of the array should be a constant.

But this seems to work perfectly under g++. To my knowledge in Standard C++ you are not allowed to use a variable during a array declaration.

If you can create dynamic arrays this way, why bother using dynamic arrays using pointers ?

e.g.

	int size;
	cin >> size;
	int * pmyarray = new int[size];


Nuwan



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]