程序老是报错 `a' was not declared in this scope10.编写…个程序,声明一个3x5的数组并初始化,具体数值可以随意.程序打印出数值,然后数值翻1番,接着再次打印出新值.编写一个函数来显示数组的内容,
来源:学生作业帮助网 编辑:作业帮 时间:2024/08/25 16:25:26
![程序老是报错 `a' was not declared in this scope10.编写…个程序,声明一个3x5的数组并初始化,具体数值可以随意.程序打印出数值,然后数值翻1番,接着再次打印出新值.编写一个函数来显示数组的内容,](/uploads/image/z/14523744-48-4.jpg?t=%E7%A8%8B%E5%BA%8F%E8%80%81%E6%98%AF%E6%8A%A5%E9%94%99+%60a%27+was+not+declared+in+this+scope10.%E7%BC%96%E5%86%99%E2%80%A6%E4%B8%AA%E7%A8%8B%E5%BA%8F%2C%E5%A3%B0%E6%98%8E%E4%B8%80%E4%B8%AA3x5%E7%9A%84%E6%95%B0%E7%BB%84%E5%B9%B6%E5%88%9D%E5%A7%8B%E5%8C%96%2C%E5%85%B7%E4%BD%93%E6%95%B0%E5%80%BC%E5%8F%AF%E4%BB%A5%E9%9A%8F%E6%84%8F.%E7%A8%8B%E5%BA%8F%E6%89%93%E5%8D%B0%E5%87%BA%E6%95%B0%E5%80%BC%2C%E7%84%B6%E5%90%8E%E6%95%B0%E5%80%BC%E7%BF%BB1%E7%95%AA%2C%E6%8E%A5%E7%9D%80%E5%86%8D%E6%AC%A1%E6%89%93%E5%8D%B0%E5%87%BA%E6%96%B0%E5%80%BC.%E7%BC%96%E5%86%99%E4%B8%80%E4%B8%AA%E5%87%BD%E6%95%B0%E6%9D%A5%E6%98%BE%E7%A4%BA%E6%95%B0%E7%BB%84%E7%9A%84%E5%86%85%E5%AE%B9%2C)
程序老是报错 `a' was not declared in this scope10.编写…个程序,声明一个3x5的数组并初始化,具体数值可以随意.程序打印出数值,然后数值翻1番,接着再次打印出新值.编写一个函数来显示数组的内容,
程序老是报错 `a' was not declared in this scope
10.编写…个程序,声明一个3x5的数组并初始化,具体数值可以随意.程序打印出数值,然后数值翻1番,接着再次打印出新值.编写一个函数来显示数组的内容,再编写另一个函数执行翻倍功能.数组名和数组行数作为参数由程序传递给函数.
#include
#include
#define SIZE1 3
#define SIZE2 5
void mul(int a,int b,double arr[a][b]);
void echo(int a,int b,double arr[a][b]);
int main(void)
{
double one[SIZE1][SIZE2] =
{
{1.1,2.2,3.3,4.4,5.5},
{6.6,7.7,8.8,9.9,10.10},
{11.11,12.12,13.13,14.14,15.15}
};
echo(SIZE1,SIZE2,one);
mul(SIZE1,SIZE2,one);
echo(SIZE1,SIZE2,one);
system("pause");
return 0;
}
void mul(int a,int b,double arr[a][b])
{
int i,n;
for(i = 0;i < a;i++)
{
for(n = 0;n < b;n++)
arr[i][n] *= 2;
};
}
void echo(int a,int b,double arr[a][b])
{
int i,n;
for(i = 0;i < a;i++)
{
printf("\n[%d]\n",i);
for(n = 0;n < b;n++)
printf("%7lg",arr[i][n]);
};
}
编译器用的是dev c++,
5:error:`a' was not declared in this scope
5:error:`b' was not declared in this scope
6:error:`a' was not declared in this scope
6:error:`b' was not declared in this scope
In function `int main()':
6:error:too many arguments to function `void echo(int,int)'
16:error:at this point in file
5:error:too many arguments to function `void mul(int,int)'
17:error:at this point in file
6:error:too many arguments to function `void echo(int,int)'
18:error:at this point in file
At global scope:
22:error:`a' was not declared in this scope
22:error:`b' was not declared in this scope
In function `void mul(int,int)':
28:error:`arr' undeclared (first use this function)
28:error:(Each undeclared identifier is reported only once for each function it appears in.)
At global scope:
31:error:`a' was not declared in this scope
31:error:`b' was not declared in this scope
In function `void echo(int,int)':
38:error:`arr' undeclared
程序老是报错 `a' was not declared in this scope10.编写…个程序,声明一个3x5的数组并初始化,具体数值可以随意.程序打印出数值,然后数值翻1番,接着再次打印出新值.编写一个函数来显示数组的内容,
经我用devcpp测试发现应该定义成
void mul(int a,int b,double arr[][SIZE2])
void echo(int a,int b,double arr[][SIZE2])
你写的不是变长数组,因为你用的SIZE1 和SIZE2是宏,宏在预处理的时候都会被换成原本的.也就是说:预处理后,SIZE1变成了3,SIZE2变成了5,这些可以在预处理后的代码里看到.