我有代码below.The问题,我使用的是一个带有一行的二维数组,2 col.The第一次用于存储值,第二次当我初始化标志时出现flag.The问题时,值也会受到影响。
#include<stdio.h>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
int arr[a][1];
int i,j,k,sum=0;
for(i=0;i<a;i++)
{
scanf("%d",&arr[i][0]);
}
for(i=0;i<a;i++)
{
printf("%d\n",arr[i][0]);
}
for(j=0;j<a;j++)
{
arr[j][1]=0;
}
for(i=0;i<a;i++)
{
printf("%d\n",arr[i][0]);//Different Values
}
}发布于 2015-06-30 17:37:23
int arr[a][1];只有一个列,而不是two.You应该使用
int arr[a][2];发布于 2015-06-30 17:36:55
在这里你写得出界了
arr[j][1]=0;这是因为您只使用一个元素写入数组的第二个元素。
arr[x]的大小(对于任何有效的x)只是一个。
发布于 2015-06-30 17:41:14
数组应该如下所示:
arr[row][col] where row denotes the number of rows and col the no of coloumns.因此,arra是一行1色的数组,因此代码工作错误。
你的阵列应该是aa。这意味着arr是一个包含一行和2 coloumn.Similarly的数组,您必须在整个代码中更改其他arr。
https://stackoverflow.com/questions/31144667
复制相似问题