zoukankan      html  css  js  c++  java
  • C++中的sizeof

    sizeof 返回一个对象或类型名的字节长度。
    注意几点:
    1、一个string的大小与它所指的字符串的长度无关;
    2、应用在指针类型上的sizeof操作符返回的是包含该类型地址所需的内存长度;
    3、应用在引用类型上的sizeof操作符返回的是包含被引用对象所需的内存长度。
    int *pi = new int[13];
    cout << "pi:\t"  << sizeof(pi)  << endl;
    cout << "*pi:\t" << sizeof(*pi) << endl;
    
    string st1("fr");
    string st2("a submarine");
    string *ps = &st1;
    cout << "st1:\t" << sizeof(st1) << endl;
    cout << "st2:\t" << sizeof(st2) << endl;
    cout << "ps:\t"  << sizeof(ps)  << endl;
    cout << "*ps:\t" << sizeof(*ps) << endl;
    
    cout << "short:  \t"  << sizeof(short)    << endl;
    cout << "short *:\t"  << sizeof(short *)  << endl;
    cout << "shout &:\t"  << sizeof(short &)  << endl;
    cout << "short[3]:\t" << sizeof(short[3]) << endl;
    
     
    输出:
    pi:     4
    *pi:    4
    st1:    32
    st2:    32
    ps:     4
    *ps:    32
    short:          2
    short *:        4
    shout &:        2
    short[3]:       6
    


    /**************************************************************************
                      原文来自博客园——Submarinex的博客: www.cnblogs.com/submarinex/               
      *************************************************************************/

  • 相关阅读:
    字符串题表
    插头dp题表
    点分治题表
    Kd-tree题表
    【BZOJ 4605】崂山白花蛇草水 替罪羊树套线段树
    假的kd-tree小结
    【BZOJ 1492】 [NOI2007]货币兑换Cash 斜率优化DP
    CDQZ 2017 游记
    【BZOJ 1146】[CTSC2008]网络管理Network
    联赛之前的题表(已完成)汇总(可能有遗漏)
  • 原文地址:https://www.cnblogs.com/submarinex/p/2077151.html
Copyright © 2011-2022 走看看