1 #include <stdio.h>
2 #include<iostream>
3
4 using namespace std;
5
6 void main(){
7 //这个时候*a存的是字符串数组的首地址
8 char* p1 = "hello";
9 char* p2 = "world";
10 char* p3 = "!!";
11 //char* a[] = {p1,p2,p3};
12 char* a[] = {"hello","world","!!"};
13
14 char** p;
15 p = a; //p指向了a,也就是将**a所指的内存赋值给p ,也就是p = &(*a);
16 p++;
17 cout << *p<<endl;
18 cout << **p<<endl;
19 }
//强行解释一波,对指针还是有点模糊,所以翻起以前的内容看看,小结一下
数组a其实就是一个字符串数组,a此时是数组名,就只指向了hello字符串的首地址(我们常常说指针指向一块内存,
其实就是指向它的首地址,例如int i = 10; int* p =&i; p指向了i这个int变量的首地址),
a数组里面存的都是字符串指针。每个指针存的都是字符串的首地址。*a 就是取a所存地址对应的值,就是 “hello”了,p指向了a ,
于是p也获取到了hello这个字符串的首地址,*p就是 “hello” 了。
原文:https://www.cnblogs.com/liuzeyu12a/p/10512613.html