对数组使用realloc成立么?

来源:百度知道 编辑:UC知道 时间:2024/05/31 23:11:15
比如
int a[10],*b;
如果再不够用的情况下我在进行
b=(int *)realloc(a,(10+5)*(int));
a=b;
成立么

int a[10],这么声明的话,a是一个常量(数组名是常量),是不允许进行再赋值的。
应该这么做:
int *a;//将a声明为一个指针

a=(int *)malloc(size);//先进行malloc

在不够用的情况下:
b=(int *)realloc(a,(10+5)*(int));
a=b;
这样是没有问题的