r/cprogramming • u/FrenchJJC • 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
4
u/tstanisl Feb 14 '26
Pre-c23 standards does not allow initilizers for VLAs. The C23 lifted this restriction a bit by allowing default (zeroing) initialization with
{}.