// // main.c // C11-指针2 // 快被自己搞吐了 // Created by apple on 15/1/8. // Copyright (c) 2015年 itcast. All rights reserved. //
#include <stdio.h>
int main(int argc, const char * argv[]) {
//定义二维数组arr,修改此处的原因是因为防止输出时常量参与计算所引起的结果相等的问题 //这样定义也可以使大家看的更直观一些 int arr[3][4]={1,3,5,7, 9,11,13,15, 17,19,21,23}; //定义指针数组p[3],该指针数组存放的是每一个元素是一个数组指针 int *p[3]={arr[0],arr[1],arr[2]}; //定义一个二维数组指针 int (*q)[4] = arr; //定义一个普通的二级指针 int *r = arr;
//p=arr=&arr[0] //p+1=arr+1=&arr[1] //p+2=arr+2=&arr[2] printf("%d\t",**arr); //1 printf("%d\t",**q); //1 printf("%d\t",**p); //1 printf("%d\t",*p[0]); //1 printf("%d\t",(*q)[0]); //1 printf("%d\n",*r); //1
printf("%d\t",**(arr+1)); //9 printf("%d\t",**(q+1)); //9 printf("%d\t",**(p+1)); //9 printf("%d\t",*p[1]); //9 printf("%d\t",*(q+1)[0]); //9 printf("%d\n",*(r+4)); //9
printf("%d\t",*((*arr)+1)); //3 printf("%d\t",*((*q)+1)); //3 printf("%d\t",*(*(p)+1)); //3 printf("%d\t",*(p[0]+1)); //3 printf("%d\t",(*q)[1]); //3 printf("%d\n",*(r+1)); //3
printf("%d\t",*(*(arr+1)+1)); //11 printf("%d\t",*(*(q+1)+1)); //11 printf("%d\t",*(*(p+1)+1)); //11 printf("%d\t",*(p[1]+1)); //11 printf("%d\t",(*(q+1))[1]); //11 printf("%d\n",*(r+5)); //11
return 0; }
|