• 指针与指针地址


       

    int urn[SIZE];

        urn[0] = 100;

        urn[1] = 200;

        urn[2] = 300;

        urn[3] = 400;

        urn[4] = 500;

        

        int *ptr1,*ptr2,*ptr3;

        ptr1 = urn;

        ptr2 = &urn[2];

        

        printf("当前指针的值和地址 ");

        printf("ptr1 = %p, *ptr1 = %d, &ptr1 = %p\n",ptr1,*ptr1,&ptr1);

        

        ptr3 = ptr1 + 4;

        printf("ptr1 + 4 = %p, *(ptr1+4) = %d\n",ptr1+4,*(ptr1+4));

        

        ptr1++;

        printf("ptr1++, ptr1 = %p, *ptr1 = %d, &ptr1 = %p\n",ptr1,*ptr1,&ptr1);

        

        ptr2--;

        printf("ptr2--, ptr2 = %p, *ptr2 = %d, &ptr2 = %p\n",ptr2,*ptr2,&ptr2);

        

        --ptr1;

        ++ptr2;

        printf("--ptr1,++ptr2, ptr1 = %p, *ptr1 = %d, ptr2 = %p, *ptr2 = %d\n",ptr1,*ptr1,ptr2,*ptr2);

        

        printf("ptr2 - ptr1, ptr2 = %p, ptr1 = %p, ptr2 - ptr1 = %d",ptr2,ptr1,ptr2-ptr1);

        printf("ptr3 = %p, ptr3 - 2 = %p\n",ptr3,ptr3-2);

     

    ptr1 = 0x7fff5fbff820,    // ptr1 指针中保持的值是:0x7fff5fbff820,它是urn数组的首地址。

    *ptr1 = 100,        // ptr1 保存的变量的值  

    &ptr1 = 0x7fff5fbff818   // ptr1 是指针类型的变量,它在内存中的地址是:0x7fff5fbff818

     

    ptr1 + 4 = 0x7fff5fbff830, *(ptr1+4) = 500

    ptr1++, ptr1 = 0x7fff5fbff824, *ptr1 = 200, &ptr1 = 0x7fff5fbff818

    ptr2--, ptr2 = 0x7fff5fbff824, *ptr2 = 200, &ptr2 = 0x7fff5fbff810

    --ptr1,++ptr2, ptr1 = 0x7fff5fbff820, *ptr1 = 100, ptr2 = 0x7fff5fbff828, *ptr2 = 300

    ptr2 - ptr1, ptr2 = 0x7fff5fbff828, ptr1 = 0x7fff5fbff820, ptr2 - ptr1 = 2   // 说明ptr2 和ptr1之间有2个Int的距离

    ptr3 = 0x7fff5fbff830, ptr3 - 2 = 0x7fff5fbff828  // 指针减去整数,指针地址改变。

  • 相关阅读:
    Generator 函数的异步应用
    Generator 函数的语法
    10 个最佳的 Node.js 的 MVC 框架
    Node.js 框架对比之 Express VS Koa
    JavaScript资源分享
    【转载】Web 研发模式演变
    学习资源整理
    超高影响力开源大放送,学习开发必备教科书
    LVS + KEEPALIVED + WINDOWS SERVER 2008 R2 ------高可用负载均衡(转)
    LVS DR模式 RealServer 为 Windows 2008 R2配置
  • 原文地址:https://www.cnblogs.com/sell/p/2845486.html
Copyright © 2020-2023  润新知