#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]
本文通过一个C++程序示例介绍了如何使用指针访问数组元素,解释了一维及二维字符数组的定义与访问方式,并展示了不同类型的指针变量及其操作。

被折叠的 条评论
为什么被折叠?



