這是否適用於C語言?使用變量定義數組的大小
#include <stdio.h>
int main()
{
int i = 5;
int a[i]; // Compiler doesn't give error here. Why?
printf("%d",sizeof(a)); //prints 5 * 4 =20. 4 is the size of integer datatype.
return 0;
}
編譯器在語句int a[i];
處沒有給出錯誤。我不是一個常量,那麼它如何成功編譯?是因爲我使用gcc編譯器嗎?它允許用C++嗎?
關於什麼是關於變長數組的常量表達式的討論,在[我的答案在這裏](http://stackoverflow.com/a/21273849/1708801)中的討論是相關的。 –