我是 C++ 及其开发的新手。我用过
static const int ipx[7][2] = { {-1, 0}, {-1, -1}, {-1, 1}, {-2, 0}, {-2, -1}, {-2, 1}, {0, 0} };
当我打印该数组的值时,我得到如下结果。谁能解释为什么会这样。谢谢
printf("-> %i \n",ipx[3][1]); // prints -> 0
printf("-> %i \n",ipx[7][1]); //prints-> 28
printf("-> %i \n",ipx[7][0]); //prints ->-> 1
printf("-> %i \n",ipx[5][1]); //prints -> 1
提前谢谢你。
最佳答案
C++ 数组是从 0 开始索引的,因此打印出 ipx[7][0]
是未定义的行为,因为索引运行 0..6
对于 7 元素大批。您可能需要 ipx[2][1]
、ipx[6][1]
、ipx[6][0]
和 ipx[4][1]
。
关于C++ 多维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29135785/