Code:
#include <stdio.h>
int main() {
int size;
scanf("%d", &size);
int foo[size];
for(int i = 0; i < size; i++)
scanf("%d", &foo[i]);
for(int i = 0; i < size; i++)
printf("%d\n",foo[i]);
return 0;
}
How does this code compile? More specifically: how does the compiler know what is the size of frame main
if size of local variable foo
is not known at compile time. I was expecting a compile error along the lines: "foo
has incomplete type"
To have also tried the code and it also runs fine: