码迷,mamicode.com
首页 > 其他好文 > 详细

指针的value

时间:2017-08-06 21:57:45      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:poi   一个   左值   移动   logs   value   end   and   array   

  1. 全局变量的默认初始化值为0,char为空字符——‘\0‘,string为"\0 "
     3 char c;
     4 string s;
     5 const int a1 = 10;
     6 
     7 int main()
     8 {
     9     cout << p << endl;
    10     cout <<"a " <<a << endl;
    11     cout <<"c "<< c << endl;
    12     cout <<"s"<< s << endl;
    13     char ch = \0;//char ch=0;
    14     cout << "ch" << ch << endl; 
    后面接2、3、4、5的代码
  2. 指针的value是所指对象的地址
    1 int a2 = 1;
    2 int *p2 = &a2;
    3 cout << p2 << " " << &a2 << endl;
  3. 二级指针的value是一级指针的地址,二级指针解引用是一级指针的value,这与一级指针解引用一致(解引用表达式的结果为左值)
    int **p3 = &p2;
    cout << p3 << " " << &p2 << endl;
    cout << *p3 << " " << p2 << endl;
  4. 指针算术移动的距离与所指对象类型有关,int型移动四个bytes,char型移动一个字节
    1 cout << p2 << " "<<p2 + 1 << endl;
  5. 指针的下标操作p[n]等价于*(p+n)
    1 int array[2] = { 1, 2 };
    2 p2 = array;
    3 cout << p2 + 1 << " " << &p2[1] << endl;
  6. 从指针去理解迭代器,iterator提供了解引用、++、--、+n、-n,但不提供下标操作;raw pointer是一种随机迭代器,vector返回的iterator实际上是T*,non-random-iterator不支持+n操作,否则与非随机矛盾。

指针的value

标签:poi   一个   左值   移动   logs   value   end   and   array   

原文地址:http://www.cnblogs.com/hchacha/p/7295877.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!