This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Declaring Arrays
- From: Nuwan Kodagoda <nuwank at sliit dot lk>
- To: gcc at gcc dot gnu dot org
- Date: Fri, 05 Mar 2004 09:52:57 +0600
- Subject: 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