C语言入门 6-9 多维数组,请大神帮我看看这个程序到底是哪里错了,运行不了
题目:
任务
以下程序中的主方法中分别定义名为arr1和arr2的两行两列的二维整型数组。arr1使用第一种初始化,arr2使用第二种初始化。分别给arr1和arr2数组元素初始化为10,20,30,40。第一行元素为10和20,第二行元素为30和40。
在代码编辑器中
第5,7行补全代码
本节为体验小节,不做正确性验证
我的代码:
2017-04-02
#include <stdio.h>
void big(int arr[2][2])
{
int i,j;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d",arr[i][j]);
}
printf("\n");
}
}
int main()
{
int arr1[2][2]={{10,20},{30,40}} ;
int arr2[2][2]; //只要把这句放到前面就可以了,这个题定义的是两个数组,所以这样写结果也是一样的
arr2[0][0]=10;
arr2[0][1]=20;
arr2[1][0]=30;
arr2[1][1]=40;
big(arr1);
printf("************\n");
big(arr2);
return 0;
}还是建议用C++的咯
Compiling...
.c
E:\练习\kal\.c(20) : error C2143: syntax error : missing ';' before 'type'
E:\练习\kal\.c(21) : error C2065: 'arr2' : undeclared identifier
E:\练习\kal\.c(21) : error C2109: subscript requires array or pointer type
E:\练习\kal\.c(21) : error C2109: subscript requires array or pointer type
E:\练习\kal\.c(21) : error C2106: '=' : left operand must be l-value
E:\练习\kal\.c(22) : error C2109: subscript requires array or pointer type
E:\练习\kal\.c(22) : error C2109: subscript requires array or pointer type
E:\练习\kal\.c(22) : error C2106: '=' : left operand must be l-value
E:\练习\kal\.c(23) : error C2109: subscript requires array or pointer type
E:\练习\kal\.c(23) : error C2109: subscript requires array or pointer type
E:\练习\kal\.c(23) : error C2106: '=' : left operand must be l-value
E:\练习\kal\.c(24) : error C2109: subscript requires array or pointer type
E:\练习\kal\.c(24) : error C2109: subscript requires array or pointer type
E:\练习\kal\.c(24) : error C2106: '=' : left operand must be l-value
E:\练习\kal\.c(25) : warning C4047: 'function' : 'int (*)[2]' differs in levels of indirection from 'int '
E:\练习\kal\.c(25) : warning C4024: 'big' : different types for formal and actual parameter 1
执行 cl.exe 时出错.
kal.exe - 1 error(s), 0 warning(s)
举报