/************************************************************************/
/* 浅析指针数组和数组指针
指针数组:array of pointers
数组指针:a pointer to an array
举例说明
int* a[4] 指针数组
表示:数组a中的元素都为int型指针
元素表示:*a[i] *(a[i])是一样的,因为[]优先级高于*
int (*a)[4] 数组指针
表示:指向数组a的指针
元素表示:(*a)[i]
*/
/************************************************************************/
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
int c[4] = { 1,2,3,4 };
int *a[4];// array of pointers
int(*b)[4];//a pointer to an array
// 1、 method base on array of pointers
for(int i = 0;i < 4;i++)
{
a[i] = &(c[i]);
}
for(int i = 0;i < 4;i++)
{
cout << "*(a[i])"<< *(a[i]) << endl;
}
//2、method base on a pointer to an array
b = &c;
for(int i = 0;i<4;i++)
{
cout <<"(*b)[i]" << (*b)[i]<< endl;
}
system("pause");
return 0;
}
参考链接
https://www.cnblogs.com/Romi/archive/2012/01/10/2317898.html