当我将ar
和&ar[0][0]
打印为指针时,我看到了相同的值。
所以我希望它们可以互换,但是事实并非如此:
int main(void)
{
#define rowsCount 4
#define colsCount 3
int ar[rowsCount][colsCount] =
{
{0, 1, 2},
{3, 4, 5},
{6, 7, 8},
{9, 10, 11},
};
int rowIndex = 1;
int colIndex = 5;
printf("TEST: %p %p\n", ar, &ar[0][0]);
printf("%d\n", ar[rowIndex][colIndex]);
printf("%d\n", *(&ar[0][0] + rowIndex * colsCount + colIndex));
printf("%d\n", *(ar + rowIndex * colsCount + colIndex));
return 0;
}