&ar [0] [0]和ar之间的区别

时间:2019-11-13 10:09:23

标签: c arrays pointers

当我将ar&ar[0][0]打印为指针时,我看到了相同的值。 所以我希望它们可以互换,但是事实并非如此:

enter image description here

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;
}

0 个答案:

没有答案