ALEXKK2011

The Technical Side of alexKK2011
  博客园  :: 新随笔  :: 订阅 订阅  :: 管理

string type & its pointer

Posted on 2011-02-22 15:02  alexkk2011  阅读(110)  评论(0编辑  收藏  举报

#include <iostream>
#include <string>

using namespace std;

void main()
{
    //exp.1
    string str[] = {"a","bc","def"};
    string *strPtr = str;
    cout << "str[] is {\"a\", \"bc\", \"def\"}" << endl;
    cout << "str is : "<< str << endl;
    cout << "*str is : " << *str << endl;
    cout << "str[0] is: " << str[0] << endl;
    cout << "&str is: " << &str << endl;
    cout << "*(int*)(str) is " << *(int*)(str) << endl;
    cout << "sizeof str is: " << sizeof(str) << endl;
    cout << "sizeof string is :" << sizeof(string) << endl << endl;
    
    cout << "*strPtr = str" << endl;
    cout << "sizeof *strPtr is : " << sizeof(*strPtr) << endl;
    cout << "sizeof strPtr is : " << sizeof(strPtr) << endl;
    cout << "*strPtr is : " << *strPtr << endl;
    cout << "strPtr is : " << strPtr << endl;
    cout << "&strPtr is : " << &strPtr << endl;

    /*
    str[] is {"a", "bc", "def"}
    str is : 0012FEF4
    *str is : a
    str[0] is: a
    &str is: 0012FEF4
    *(int*)(str) is 0
    sizeof str is: 96
    sizeof string is :32

    *strPtr = str
    sizeof *strPtr is : 32
    sizeof strPtr is : 4
    *strPtr is : a
    strPtr is : 0012FEF4
    &strPtr is : 0012FEE8
    请按任意键继续. . .
    */
}