由于要用整型常量定义数组,我就用const定义了数组长度,结果编译错误:
#include
#include
/*#define n 5*/
int main()
{
const int n=5;
int rest[n] = {0,0,0,0,0};
printf("%d", rest[0]);
return 0;
}
error: variable-sized object may not be initialized
但当我用宏常量定义时就可以,这是为什么呢?难道不变的变量不是常量?常量不就是不变的量吗?
#include
#include
#define n 5
int main()
{
/*const int n=5;*/
int rest[n] = {0,0,0,0,0};
printf("%d", rest[0]);
return 0;
}
小弟菜鸟一枚,还请大家帮帮忙:)