zoukankan      html  css  js  c++  java
  • C++:const sizeof 及array的学习笔记

    #include <iostream>
    #include 
    <stdlib.h>

    using namespace std;

    ///////////////////////////////////////////////////////////
    void TestPointArray();
    //////////////////////////////////////////////////////////

    void TestConstRef()
    {
      
    int a = 100;
      
    const int &= a;
      cout
    <<b<<endl; // 100  
      a = 2;
      cout
    <<b<<endl;  // 2
      
    //  b = 1; // error
      const int &= 300;
      cout
    <<c<<endl;
    }


    void TestSizeof()
    {
      
    char s1[6= "ABCDE";
      
    char *s2 = "abcde";
      
    char s3[] = "abcde";
      
      cout
    <<sizeof(s1)<<endl; // 6
      cout<<sizeof(s2)<<endl; // 4
      cout<<sizeof(s3)<<endl; // 6
    }


    void TestArray()
    {
      
    int a[] = {12345};
      
    int *= a;
      
      cout
    <<p<<endl; // 0x22ff50
      cout<<*p++<<endl;
      cout
    <<p<<endl; // ?
      cout<<- a<<endl; // ?
      cout<<*++p<<endl; // 3
      cout<<*(p + 1)<<endl;
      cout
    <<*((int*)((char *)p + 1))<<endl; // 哈哈, 是 0x4000 
    }


    void TestArrPara(int a[5])
    {
      cout
    << *(a++)<<endl; // OK
    }


    int main(int argc, char *argv[])
    {
    //  TestConstRef();
    //  TestSizeof(); 
    //  TestArray();
      
      
    int a[] = {12345};
    //  TestArrPara(a);
      TestPointArray();
      
      system(
    "PAUSE");    
      
    return 0;
    }



    void TestPointArray()
    {
      
    int a[] = {12345};
      
    int (*p)[5];
      p 
    = &a;
      cout
    <<*p[0]<<endl;
      cout
    <<*p[1]<<endl;
      cout
    <<*p[2]<<endl;
      cout
    <<*p[3]<<endl;
      cout
    <<*p[4]<<endl;

      cout
    <<endl;
      cout
    <<(*p)[0]<<endl;
      cout
    <<(*p)[1]<<endl;
      cout
    <<(*p)[2]<<endl;
      cout
    <<(*p)[3]<<endl;
      cout
    <<(*p)[4]<<endl;

      cout
    <<endl;
      cout
    <<p[0]<<endl;
      cout
    <<p[1]<<endl;
      cout
    <<p[2]<<endl;
      cout
    <<p[3]<<endl;
      cout
    <<p[4]<<endl;
      
      cout
    <<endl;
      cout
    <<+ 0<<endl;
      cout
    <<+ 1<<endl;
      cout
    <<+ 2<<endl;
      cout
    <<+ 3<<endl;
      cout
    <<+ 4<<endl;
      
      cout
    <<endl;
      
    int *= *p;
      cout
    << *++q<<endl;

    }

  • 相关阅读:
    f.lux
    Gidot TypeSetter (排版助手) 3.1.1.2
    FastStone Image Viewer --- 图片查看器
    www.nocmd.com 精品软件 坚持绿色之路 共筑生态之基
    Geek Uninstaller 1.4.5.136 卸载工具绿色版
    在线统计,在线调查意见,在线报名 --- 麦客
    QQ群管理 --- 免费提取QQ群所有成员
    8个在线接收手机短信验证码的免费网络服务整理
    微信群成员导出工具2.3下载 & 歪碰微信成员导出工具
    安装VSTO环境的方法
  • 原文地址:https://www.cnblogs.com/qkhh/p/1038938.html
Copyright © 2011-2022 走看看