C語言:指針和數組記號

對於指向一塊堆內存的指針變量,還可以使用數組記號來存儲相同類型的幾個數據項.
針對於上述,如*(point+i)與point[i]的效果是完全相同的;前者爲指針記號,後者爲數組記號,兩者等價;

示例:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int *point = (int*)malloc(sizeof(int) * 20);

    for (int i = 0; i <= 20; i++)
    {
        *(point + i) = i;//指針記號法
        printf("p(%02d)=%02d  Address=0x%08x\t\t", i, *(point + i), point + i);

        point[i] = i;//數組記號法
        printf("p(%02d)=%02d  Address=0x%08x\n", i, point[i], point + i);
    }
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章