C中这样定义二维数组哪错了?

来源:百度知道 编辑:UC知道 时间:2024/05/21 12:10:21
main()
{
int n;
int i;
printf("please input n: \n");
scanf("%d",&n);
int a[n][2];
for(i=0;i<n;i++)
{
scanf("%d %d",&a[i][0],&a[i][1]);
}
}

编译的时候
error C2143: syntax error : missing ';' before 'type'
error C2065: 'a' : undeclared identifier
error C2109: subscript requires array or pointer type
error C2109: subscript requires array or pointer type
error C2102: '&' requires l-value
error C2109: subscript requires array or pointer type
error C2109: subscript requires array or pointer type
error C2102: '&' requires l-value

这8个错误 我把一开始int a[n][2]改成int a[10][2]还是一样的错.

1.少了头文件 stdio.h
2.int a[n][2]; 一维可以不写,但是这里你不要搞混淆,在这个地方必须得是个常量,而这里的n是个变量.

C文件里对变量的定义要放在前面

少了头文件吧!

#include<stdio.h>之类的文件