第13章 高级指针
指针的各种定义方法
注意c语言符号优先级:.的优先级高于 “*”()高于[ ];[ ]高于星号;函数( )高于星号;
int abc();//返回值为int类型的函数
int abc[3];//int 型数组
int **bac();//返回值为“int型指针的指针”的函数 注意()的优先级大于“*”
int (*abc)();//返回值为int的函数指针
int (*abc)[6];//指向“int型数组”的指针 注意:int *abc[6]=>指针数组,数组中的元素都是指针
int *abc();//返回值为int型指针的函数
int **(*abc[6])();//指向“返回值为int型指针的指针的函数”的指针的数组
//1.int (*abc[6])int型指针数组2.int (*abc[6])() 指向返回值为int型函数的指针数组3.2.int **(*abc[6])() 指向“返回值为int型指针的指针的函数”的指针的数组
int **abc[6];//int型指针的指针数组(数组中存放的是int类型指针的指针)
int *(*abc)[6];//指向“int型指针数组”的指针
int *(*abc())();//返回值为“返回值为int类型指针的函数指针”的函数
int (**(*abc)())();//返回值为“返回值为(int的函数)指针的指针”的函数指针
//declare abc as pointer to function returning pointer to pointer to function returning int
int(*(*abc)())[6];//返回值为”指向int数组的指针“的函数指针
int *(*(*(*abc)())[6])(); //返回值为“指向’返回值为int型指针的函数指针‘的数组的指针”的函数指针
//declare abc as pointer to function returning pointer to array 6 of pointer to function returning pointer to int
对于struct
typedef struct{
int x;
int y;
}point;
point p;
point *a=&p;
point **b=&a;
问题:下面各个表达式的值
1)a :p的地址
2)*a: p的全部值(两个字段)。
3)a->x :p的x域的值。
4)b:变量a的地址。
5)b->a:非法
6)b->x:非法
7)*b :存储在a中的值,即p的地址
8)*b->a:非法
9)*b->x:非法
10)b->a->x:非法
11)(*b)->a :非法
12)(*b)->: a.x
13)**b:b给出了a的值,所以这等价于a,它给出了(两个字段)的整个值
对于不熟悉的指针定义可以上网搜cdecl程序。它可以在c语言的声明和英语之间进行转换。