如果你对指针数组和数组指针有很大疑惑,最好的办法就是自己写一些测试代码来验证自己的想法,以下是一段测试程序代码:
#include "stdafx.h"
#include<iostream>
#include<Windows.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char * pszArr[2] = {0}; //指针数组
char (*pszChar)[2] = NULL;//数组指针
char szArr[2] = "2";
cout<<"sizeof(pszArr) : "<<sizeof(pszArr)<<endl;
cout<<"sizeof(pszChar) : "<<sizeof(pszChar)<<endl;
pszArr[0] = "0000000000";
pszArr[1] = "1111111111";
pszChar = &szArr;
cout<<"pszArr[0]: "<<pszArr[0]<<endl;
cout<<"pszArr[1]: "<<pszArr[1]<<endl;
cout<<"pszChar: "<<pszChar<<endl;
cout<<"*pszChar: "<<*pszChar<<endl;
while(1)
{
::Sleep(100);
}
return 0;
}
然后看看这段函数的执行结果:
Sizeof(pszArr) : 8
Sizeof(pszChar) : 4
pszArr[0]: 000000000
pszArr[1]: 1111111111
pszChar: 0013FF44
*pszChar: 2
从输出的结果我们可以看出:
指针数组就是一种数组,而这种数组里面存放的是指针,
指针数组是一种指针,这种指针指向的是数组的地址,类似一个二级指针(指向指针的指针)
pointer data