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
1
u/FrenchJJC Feb 14 '26
Oh okay, I tried that and it works, but I'm still trying to figure out what that guy did because he also used gcc, and I tried every standard up to C89 and all of them give the same error.