why a[n] is accepted in c during runtime?

后端 未结 4 1899
半阙折子戏
半阙折子戏 2021-01-12 02:39

why can we do this in c?

int n;
scanf(\"%d\",&n);
int a[n];

I thought array is located memory during load time but seems like the above

4条回答
  •  独厮守ぢ
    2021-01-12 03:31

    I am no expert in C, but this could be a variable-length array as added by C99 and supported by GCC, for example. GCC allocates the memory for such array on stack, so that it gets automatically freed when you return from the function.

提交回复
热议问题