int main()
{
const int x = 4;
int row, col, j;
int myArray[x][x], *xptr;
for (row = 0; row < 4; row++){
for (col = 0; col < 4; col++){
myArray[row][col] = (row * 4) + col;
}
}
printf("contents of myArray... \n");
/* set xptr to the front of myArray*/
xptr = &(myArray[0][0]);
/*Print out the contents of the array. */
for (row = 0; row < 4; row++) {
for (col = 0; col < 4; col++) {
printf("%d ", *(xptr + (row * 4) + col));
}
}
printf("\n");
/* Print out contents again, this time increment the pointer. */
printf(" Contents of the x array again... \n");
/* Set xptr to the front of the x array. */
xptr = &(myArray[0][0]);
/*print out the contents of the array. */
for (j = 0; j< 16; j++);
printf("%d ", *xptr);
xptr++;
}
}
我无法使用指针作为打印地址重新打印数组。 IE,根据我的教授的说明,我应该得到 x数组的内容......
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
x阵列的内容......
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
但我得到了
contents of myArray...
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
contents of the x array again...
0
然后结束。我试过玩一切,但我不确定是什么给我这个错误
感谢, Creecher
答案 0 :(得分:1)
for (j = 0; j< 16; j++);
在行尾看到额外的分号?
对于第二个循环,看起来你的大括号也不对。