一个关于二维指针的问题

#include<iostream.h>

 void main()
 {		
	char *p[]={"comm","digi","auto","tele","elec"};
	char **q[]={p+2,p, p+4, p+1, p+3};

	for (int i=0; i<5; i++)
	{
		cout<<&p[i]<<":"<<p[i]<<endl;
	}

	cout<<"The address of q"<<endl;
	for (int j=0; j<5; j++)
	{
		cout<<q[j]<<":"<<*q[j]<<endl;
	}
	
	cout<<q[3][1]<<endl;		//<=>cout<<*(*(q+3)+1)<<endl;
	cout<<*q[1]<<endl;		//<=>cout<<**(q+1)<<endl;
	cout<<**(q+4)<<endl;		//<=>cout<<*q[4]<<endl;
	cout<<*(*(q+1)+1)<<endl;	//<=>cout<<q[1][1]<<endl;
	cout<<*(q[3]+3)<<endl;		//<=>cout<<*(*(q+3)+3)<<endl;
 }

上述代码的输出为:

0x0018FF34:comm
0x0018FF38:digi
0x0018FF3C:auto
0x0018FF40:tele
0x0018FF44:elec
The address of
0x0018FF3C:auto
0x0018FF34:comm
0x0018FF44:elec
0x0018FF38:digi
0x0018FF40:tele

auto
comm
tele
digi
elec
内存模型为:

一个关于二维指针的问题_第1张图片

你可能感兴趣的:(一个关于二维指针的问题)