首页 > 解决方案 > C中数组的动态分配

问题描述

总是教导说,在 C 中运行时不能分配数组的大小。我运行了一个代码来检查这一点,我的代码可以工作。我不明白这一点。为什么?

int n;
int a[n];      //here should be error, but its not//
scanf("%d", &n );
for(int i = 0; i < n; i++)
scanf("%d", &a[i] );
for(i = 0; i < n; i++)
printf("%d", a[i] );

这应该会引发错误,因为应该在编译之前声明数组的大小,但事实并非如此。

标签: arrayscdynamicdeclarationconcept

解决方案


推荐阅读