Array definition – Expression must have a constant value

In C language keyword const has nothing to do with constants. In C language, by definition the term “constant” refers to literal values and enum constants. This is what you have to use if you really need a constant: either use a literal value (define a macro to give your constant a name), or use a enum constant.

(Read here for more details: Shall I prefer constants over defines?)

Also, in C99 and later versions of the language it possible to use non-constant values as array sizes for local arrays. That means that your code should compile in modern C even though your size is not a constant. But you are apparently using an older compiler, so in your case

#define SIZE 10

is the right way to go.

Leave a Comment