int *p[2];是一个指向int的指针数组,即每个元素都是一个指针
#include <string> #include <iterator> #include <iostream> #include <algorithm> using namespace std; int main() { int a[] = {1,2,3,4,5}; int b[] = {10,20,30,40,50}; int *p[2]; p[0] = a; p[1] = b; for(int i = 0; i < 5; i++) cout << *p[0] + i << endl; for(int i = 0; i < 5; i++) cout << *p[1] + i << endl; }
int (*p)[2]是指向两个元素的指针
#include <iostream> using namespace std; void main() { int (*p)[2]; int b[3][2] = {{1, 2}, {3, 4}, {5, 6}}; p = b; for(int i = 0; i < 3; i++) { for(int j = 0; j < 2; j++) cout << p[i][j]; //cout << *(*(p+i)+j); cout << endl; } }