I just did a experiment yesterday, and find something confusing:
#include <stdio.h>
int main()
{
int j;
scanf("%d",&j);
const int i = j;
int arr[i];
return 0;
}
The number j
is read from keyboard and it’s used to allocate the array arr
on the stack.
The compiler does not even know the size of the array at compile time (initializes j to 0?), but there is no compilation error. How is it possible?