Pointer to Function

Posted on 2007-02-14 04:29  QT_pixy  阅读(643)  评论(0)    收藏  举报

Complex Declaration
这些复杂的定义看似好象有些孔乙己的做法,其实不然,这些关于pointer的练习是很重要的,一定要弄明白的。The c programming language这本书的5.11和5.12章节就在讲述这些复杂的定义。其实也不算复杂,有一定的规律可以遵循,但首先要理解这些定义。理解这些对于pointer的使用非常重要。C比JAVA难就难在语法简单,越是简单的语法就越蕴涵着千变万化,就好象围棋一样,规则简单却蕴涵着很深的棋道。只有彻底理解了pointer才能熟练掌握它的千变万化。

int (*foobar(char **, void *(*)(int,float)))();
“foobar” is a function with two arguments
1: a pointer to pointer to char
2: a pointer to a function taking an int and float and returning a pointer to void
It returns a pointer to a function returning int

void (*func(void))(int)
func is a function with no arguments returning pointer to function with an int argument and no return value

void (*f[])(char *, int)
f is array[] of pointer to functions with two arguments
1: a point to char
2: an int
It returns void

int **x1;
x1 is a pointer to pointer to int

int *x2[13];
x2 is array[13] of pointer to int

int (*x3)[13];
x3 is a pointer to array[13] of int

int (*x4)();
x4 is a pointer to a function returning an int

int *x5();
x5 is a function returning a pointer to int

int (*x6())();
x6 is a function returning a pointer to function returning an int

char (*(*x())[])();
x is a function returning a pointer to array[] of pointer to functions returning char

char (*(*x[3])())[5];
x is array[3] of pointer to function returning pointer to array[5] of char

int (*(*x())[])();
x is a function returning a pointer to array[] of pointer to function returning int

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3