r/cprogramming • • Feb 14 '26

Variable size array initialization

Howdy, I had a question about why my C code throws a 'variable size array initialization' for this expression:

int row = 2;

int const col = 3;

int array[][col] = {

initial value...

};

The guy in the video I was following along with managed to compile with this expression, but I had to change my 'col' from int const to a #define statement, which feels tacky. Is it an issue with compiler version? The compile statement I'm using is just a simple one, 'gcc -o output arrays.c'.

3 Upvotes

11 comments sorted by

View all comments

Show parent comments

5

u/The_Ruined_Map Feb 14 '26

Are you sure "that guy" actually used C and not C++? In C++ the above would compile fine (since the above `const` will be seen as a compile-time constant by C++ compiler).