# Constant array size



## alman9898 (Apr 23, 2008)

I know in C, arrays have to of a constant size.

However when I do something like:

const int size = 10;
int list[size];

I get thrown an error that the array size must be a constant expression (at the line where the array is declared). However, when in C++ when I do this it compiles fine. I'm using Visual Studio 2005, by the way.

However, when I switch to "Compile as C++ code" it compiles the .c file correctly. So is this valid for any C code, or just the Visual Studio compiler?


----------



## ShosMeister (Jan 19, 2008)

Alman, welcome!! I haven't looked specifically at the differences between C and C++, but, if I remember, that is correct that in C++ it detects that size is an INT and it compiles okay. There are ways of creating dynamic arrays if you need that using malloc and such.


----------

