arrays - 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] );
这应该会引发错误,因为应该在编译之前声明数组的大小,但事实并非如此。
解决方案
推荐阅读
- puppet - Deep hiera lookup in a ruby template returns last result only
- node.js - 使用 nodejs 从 newman 加载 csv
- python - Adding values from one list to another when they share value
- html - 如何将固定高度的div中的元素垂直对齐?
- c# - 即使我之前声明过我的变量声明也没有检测到
- java - JavaFX 图表未正确分层
- java - 选择要继续的实例
- python - 比较向量列表
- javascript - 在 Gridview 中启用/禁用文本框
- pyspark - 如何在数据框的开头移动 pyspark 数据框的特定列