[問題] 使用struct宣告的矩陣
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
dec-c++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
#include <cstdlib>
#include <iostream>
問題(Question):
struct str
{
int size;
int direction;
};
int main()
{
str fgu[3][3];
for(int x=0;x<=3;x++)
for(int y=0;y<=3;y++)
fgu[x][y].size=0;
fgu[1][0]=9;
for(int y=0;y<=3;y++)
{
for(int x=0;x<=3;x++)
{
cout<<fgu[x][y].size<<" ";
}
cout<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
預期的正確結果(Expected Output):
0 9 0 0
0 0 0 0
0 0 0 0
0 0 0 0
錯誤結果(Wrong Output):
0 9 0 0
0 0 0 0
0 0 0 0
9 0 0 0
這問題感覺很淺...可是我花了好多時間 還是沒解決...
錯的那兩個9 難道記憶體位址是一樣的嗎
拜託各位大大了 謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.37.196.82
→
06/15 00:59, , 1F
06/15 00:59, 1F
→
06/15 01:01, , 2F
06/15 01:01, 2F
→
06/15 01:04, , 3F
06/15 01:04, 3F
→
06/15 01:04, , 4F
06/15 01:04, 4F
→
06/15 01:05, , 5F
06/15 01:05, 5F
→
06/15 01:05, , 6F
06/15 01:05, 6F
→
06/15 01:06, , 7F
06/15 01:06, 7F
→
06/15 01:08, , 8F
06/15 01:08, 8F
→
06/15 01:15, , 9F
06/15 01:15, 9F
→
06/15 01:24, , 10F
06/15 01:24, 10F
→
06/15 02:00, , 11F
06/15 02:00, 11F
→
06/16 08:29, , 12F
06/16 08:29, 12F
推
06/16 10:14, , 13F
06/16 10:14, 13F