[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\n", 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\n",*a);// 0
    printf("a[1]->%d\n", *(a + 1));// 1
    printf("a[2]->%d\n", *(a + 2));// 2
    int(*p)[10];
    //p = a;  error: "int*" can not be assigned to "int(*)[10]"
    p = &a;
    printf("**p->%d\n", **p);// 0
    printf("(*p)[0]->%d\n", (*p)[0]);// 1

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

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

    system("pause");
}

 


 

转载于:https://www.cnblogs.com/tianhangzhang/p/4869943.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值