您的位置:首页 > 其它

指针数组再理解

2012-11-27 11:00 204 查看
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
char* a[] = {"hello", "the", "world"};
char b[] = "hello";
char** p = a;
p++;
cout << *p << endl;
cout << **p << endl;
cout << b[2] << endl;
return 0;
}

运行结果:

the
t
l


若char b[] = {"hello"}即char b[] = "hello",则b[0] = 'h',b[1] = 'e'。

而上程序的第一行定义,可以看成一个二维数组,a[0放的是hello,a[1]放的是the。。。a[0][0]放的是h,a[0][1]放的是e。。。

所以a是一个二级指针,p也是,一次解引用只能获得行数组a[0]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: