了解C中变量作为数组大小的用法

我试图了解范围界定的不同之处:

//global scope
int size = 4;
int array[size]; // error: variably modified 'array' at file scope

int main(void) {
  int buff[size]; // works!
}

how does using a variable as array size doesn't work globally but works inside main? It would work if I use a macro instead.

Also, does using const matter for size?

评论