【语法】sizeof 笔记

来源:互联网 发布:python常用函数 编辑:程序博客网 时间:2024/06/04 19:46

 

 

 

#include <iostream>
#include 
<string>
using namespace std;

int main(int argc, char* argv[])
{
    cout 
<< "sizeof(string) = " << sizeof(string<< endl;
    
string str[] = {"sdf4""123""d"};
    
string str4[4= {"str33""mmmmm"};
    cout 
<< "sizeof(str) = " << sizeof(str) << endl;
    cout 
<< "sizeof(str4) = " << sizeof(str4) << endl;

    
string *pStr = new string[2];
    pStr[
0= "us";
    pStr[
1= "cn";
    cout 
<< endl;
    cout 
<< "sizeof(pStr) = " << sizeof(pStr) << endl;
    cout 
<< "sizeof(*pStr) = " << sizeof(*pStr) << endl;

    cout 
<< endl;
    
char b[] = "fcdg123";
    cout 
<< "b = " << b << endl;
    cout 
<< "sizeof(b) = " << sizeof(b) << endl;
    cout 
<< "*b = "<< *<< endl;
    cout 
<< "sizeof(*b) =" << sizeof(*b) << endl;

    cout 
<< endl;
    
char *= "fcdg123";
    cout 
<< "c = " << c << endl;
    cout 
<< "sizeof(c) = " << sizeof(c) << endl;
    cout 
<< "*c = "<< *<< endl;
    cout 
<< "sizeof(*c) =" << sizeof(*c) << endl;
    
return;
}

 

sizeof(string= 16
sizeof(str) = 48
sizeof(str4) = 64

sizeof(pStr) = 4
sizeof(*pStr) = 16

= fcdg123
sizeof(b) = 8
*= f
sizeof(*b) =1

= fcdg123
sizeof(c) = 4
*= f
sizeof(*c) =1
原创粉丝点击