该程序崩溃了。 C 语言中使用 n 长度数组有限制吗? 它在 C++ 中工作(使用 cin cout)。感谢您抽出时间。
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int n;
printf("n\n");
scanf("%d\n",n);
int arr[n];
system("PAUSE");
return 0;
}
最佳答案
您的代码还有另一个问题:
scanf("%d\n", n);
// ^^
// should be &n
scanf
在传递 int
时需要一个指针。
关于c++ - C 和 C++ 中的变长数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17221492/