如下,写了一个结构体数组,想计算出里面的数,但结果为1,WHY?
-----------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
int main()
{
struct stu{
int a;
int b;
char c;
};
struct stu abc[2][3]={
{1,2,'a'},{2,3,'b'},{3,4,'c'},
{10,20,'d'},{20,30,'e'},{30,40,'f'}
};
int i=0,k=0;
for(i=0;i<3;i++)
k+=abc[0][i].a;
printf("%d\n",k);
system("pause");
return 0;
}
-------------------------------------------------------------------------------------------
我原来觉得随着i的增加,应该取到1.2.3三个值,结果为6才对,但结果为1,为什么呢?
|