c语言指针数组和数组指针

 1 #include<stdio.h>
 2 #include<iostream>
 3 using namespace std;
 4 int main(){
 5     int a[2][3],*p[3]; //指针数组,存放的是int类型的
 6     int cnt=1;
 7     for(int i=0;i<2;i++)
 8         for(int j=0;j<3;j++)
 9             a[i][j]=cnt++;
10     cout<<a<<endl;
11     cout<<a[0]<<endl;
12     cout<<a[0][0]<<endl;
13     int (*q)[3];//数组指针,存放的是一个一维数组的指针变量
14     q=a; 
15     //二维数组的数组名 a 指向一维数组 a[0]的首地址,虽然值和 a[0]相同,但是类型不同
16     p[0]=a[0];
17     cout<<q<<endl;
18     cout<<p[0]<<endl;
19 }

 

posted @ 2020-02-14 17:12  ISGuXing  阅读(402)  评论(0编辑  收藏  举报