我尝试制作一个总结二维数组的程序。这些价值预先加载在整个财产安排中
#include <stdio.h>
#include <conio.h>
/*PROGRAM EJERC102 */
const int m1[2][2]={ {3,1},{4,5} };
const int m2[2][2]={ {1,3},{4,2} };
const int m3[2][2];
int f, c;
int main(){
for (f=0; f <= 1; f++)
for (c=0; c <= 1; c++)
{
m3[f][c]=(m1[f][c] + m2[f][c]); // Why is an assignment of read-only location?
printf ("(%d,%d)",f,c);
printf ("%d\n",m3[f][c]);
}
getch();
return 0;
}
答案 0 :(得分:0)
您正在设置const int类型的数组,因此main函数将其视为只读值。只需删除第三个数组声明中的const:
#include <stdio.h>
/*PROGRAM EJERC102 */
const int m1[2][2]={ {3,1},{4,5} };
const int m2[2][2]={ {1,3},{4,2} };
int m3[2][2];
int f, c;
int main(){
for (f=0; f <= 1; f++)
for (c=0; c <= 1; c++)
{
m3[f][c]=(m1[f][c] + m2[f][c]); // Why is an assignment of read-only location?
printf ("(%d,%d)",f,c);
printf ("%d\n",m3[f][c]);
}
getchar();
return 0;
}