数组指针,二级指针
2015-09-29 22:17
337 查看
char* a[] = {"hello", "the", "world"}; //1 char** pa =a; //2 //pa++; //3 cout << pa <<endl; //4 cout << *pa <<endl; //5 cout<<**pa<<endl; //6
最近看到这段代码,复习数组指针知识,做个记录备忘。
1. a是一个数组,里边存了若干个char型指针,等同于char *p = “hello”,然后把p(等于char*)存到a里边以此类推存完后2个。
2. 数组a的首地址复制给pa。由于a是个char*类型,用pa存a的地址需用char**。
3. pa++相当于a[1]。
4. 输出是数组a的地址。
5. *pa是数组第一个值相当于pa[0];*(pa+1)相当于pa[1];
6. **pa相当于pa[0][0],字符串第一个字母。
char* a[] = {"hello", "the", "world"}; //1 char** pa =a; //2 cout<<a<<endl; cout<<(&a)<<endl; //3 cout<<&a+1 <<endl; //4 cout<<"_______________________" <<endl; cout<<pa<<endl; //5 cout<<pa+1 <<endl; //63,4 输出为
a
0x0015fb28
[0]: 0x00db783c "hello"
[1]: 0x00db7838 "the"
[2]: 0x00db7830 "world"
&a
0x0015fb28
[0]: 0x00db783c "hello"
[1]: 0x00db7838 "the"
[2]: 0x00db7830 "world"
&a+1 //a中存储char*类型元素共三个,3*4占12个字节,&a指针将12个字节的存储单元看成一个整体,+1按照12个字节跳转
0x0015fb34
[0]: 0xcccccccc <错误的指针>
[1]: 0xcccccccc <错误的指针>
[2]: 0x0015fb48 ""
pa
0x0015fb28
pa+1
0x0015fb2c
pa的类型为char** 四个字节,所以与&a+1不同
水平有限,有问题大家一定要指出来,共同提高。
相关文章推荐
- 04.C语言运算符
- CoreText的绘制流程-转
- leetcode263 : Ugly Number
- 验证视图状态 MAC 失败。如果此应用程序由网络场或群集承载,请确保 <machineKey> 配置指定了相同的...
- Lecture5-2Effective number of lines
- 常用的Javascript表单正则验证函数
- 03.C语言Scanf函数
- java一切皆对象的理解,以及new关键字的理解
- 条件编译
- B\S备忘录番外篇——啊!这是一篇总结!
- 状态模式
- 例题5.2 独轮车 UVa10047
- XA两阶段提交协议
- shell 玩转文件描述符 和 重定向
- The Bus Driver Problem
- 禅与 Objective-C 编程艺术(Zen and the Art of the Objective-C Craftsmanship)
- light oj 1281 - New Traffic System (最短路+dp思想)
- 观影会
- 友元实例:友元类及友元函数
- STM32固件库3.5+uCOS2.86移植(转自暴走的工程师)