码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-10-11 21:32:41      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:

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

技术分享

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

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!