[C++] the pointer array & the array's pointer

int *p[4]------p是一个指针数组,每一个指向一个int型的
int (*q)[4]---------q是一个指针,指向int[4]的数组 --> type: int(*)[4]

void main(){

    // the pointer array
    char* arry[] = { "hello", "world", "haha" };

    for (int i = 0; i < 3; i++){
        printf("string:%s,address:%p
", arry[i], arry[i]);
    }

    // the array's pointer 
    int a[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    printf("a[0]->%d
",*a);// 0
    printf("a[1]->%d
", *(a + 1));// 1
    printf("a[2]->%d
", *(a + 2));// 2
    int(*p)[10];
    //p = a;  error: "int*" can not be assigned to "int(*)[10]"
    p = &a;
    printf("**p->%d
", **p);// 0
    printf("(*p)[0]->%d
", (*p)[0]);// 1

    printf("*(*p + 1)->%d
", *(*p + 1));// 1
    printf("(*p)[1]->%d
", (*p)[1]);// 1

    printf("*(*p + 2)->%d
", *(*p + 2));// 2
    printf("(*p)[2]->%d
", (*p)[2]);// 1
    //size
    printf("sizeof(p)->%d
", sizeof(p));// 4
    printf("sizeof(*p)->%d
", sizeof(*p));// 40

    system("pause");
}


原文地址:https://www.cnblogs.com/tianhangzhang/p/4869943.html