我寫了這段代碼,但輸出結果並不是我所期望的。我將整數:proj.startP
設置爲1000
,但在執行一些for循環後,該變量再次設置爲0
。結構中的整數設置爲零
#include <stdio.h>
struct vezelstruct{
float verd[10][10][10];
int startP;
};
struct vezelstruct proj;
int main(int argc, char *argv[])
{
int g, i;
proj.startP=1000; // variable set to 1000
printf("%i\n", proj.startP);
for(g=1;g<=10;g++)
{
for(i=1;i<=10;i++){
proj.verd[g][10][i]=0.0;
}
}
printf("should be 1000: %i\n", proj.startP); // it's equal to 0 here
return 0;
}
我在做什麼錯在這裏?
索引從0開始!!! – nhahtdh 2013-02-12 08:05:03