zoukankan      html  css  js  c++  java
  • a simple pointer example

    #include<iostream>
    using namespace std;
    
    int main()
    {
        double price[] = {75, 125,188};
        short count[] = { 5, 3, 1 };
    
        double *pr = price;
        short *ct = &count[0];
    
        cout << "pr = " << pr <<" , " << "*pr = " << *pr << "\n";
        pr = pr + 1;
        cout << "now pr = " << pr << " , " <<"*pr = " << *pr <<"\n";
    
        cout << "access two element with array notation\n";
        cout << "count[0] = " << count[0] << endl;
        cout << "count[1] = " << count[1] << endl;
        cout << "access two element with pointer notation\n";
        cout << "*count = " << *count << " , *(count + 1) = " << *(count + 1) << endl;
    
        cout <<"size of count is " << sizeof(count) << endl;
        cout << "size of *ct is " << sizeof(ct) << endl;
        return 0;
        
    }

    result:

    pr = 0x22fe10 , *pr = 75
    now pr = 0x22fe18 , *pr = 125
    access two element with array notation
    count[0] = 5
    count[1] = 3
    access two element with pointer notation
    *count = 5 , *(count + 1) = 3
    size of count is 6
    size of *ct is 8

  • 相关阅读:
    一个别人的心得(转发的)
    常见的游戏设计技术
    查看更新
    xml,json和各种序列化工具的对比
    python游戏环境搭建
    快速制作游戏
    子网和掩码
    nat
    pycharm使用技巧
    IP的面向无连接状态
  • 原文地址:https://www.cnblogs.com/TadGuo/p/7566276.html
Copyright © 2011-2022 走看看