代碼1
const int size = 9;
char c[size];
1.VS2005 編譯為 C 代碼(/TC)
編譯不通過
錯誤 1 error C2057: expected constant expression
錯誤 2 error C2466: cannot allocate an array of constant size 0
錯誤 3 error C2133: 'c' : unknown size
編譯通過
3.Cygwin gcc/g++
編譯通過
================================================
代碼2
int temp = 9;
const int size = temp;
char c[size];
1.VS2005 編譯為 C 代碼(/TC)
編譯不通過
錯誤 1 error C2057: expected constant expression
錯誤 2 error C2466: cannot allocate an array of constant size 0
錯誤 3 error C2133: 'c' : unknown size
編譯不通過
錯誤 1 error C2057: expected constant expression
錯誤 2 error C2466: cannot allocate an array of constant size 0
錯誤 3 error C2133: 'c' : unknown size
3.Cygwin gcc/g++
編譯通過
================================================
代碼3
int size;
scanf("%d", &size);
char c[size];
1.Cygwin gcc/g++
編譯通過
但不能對數組初始化。
2.VS2005
編譯不通過