Han*_*sir 0 c dev-c++ visual-studio
为什么以下代码使用Dev-C++编译器而不是Visual Studio编译?
任何的想法?这是代码:
#include<stdio.h>
main(){
int n,i;
scanf("%d",&n);
int arr[n];
for(i= 0 ; i <n ; i++)
{
//Do something with the array
}
fflush(stdin);
getchar();
}
Run Code Online (Sandbox Code Playgroud)
以下是错误:
这个:
int arr[n];
Run Code Online (Sandbox Code Playgroud)
无效,因为n它不是常量表达式.您需要在堆上分配可变大小的数组malloc(然后在完成后释放它们free).
如果您尝试使用.cpp扩展名编译它,则main必须具有返回类型int.如果您尝试使用.c扩展编译它,则需要使用c样式的局部变量声明并在函数顶部声明所有局部变量.
| 归档时间: |
|
| 查看次数: |
1480 次 |
| 最近记录: |