您的位置:首页 > Web前端

what's the difference between int (* f [])(); and int f[]();

2012-11-06 21:20 363 查看
i find this in Pointers on C
int f[]();  /*this one is illegal*/因为f[][]这个表示数组的数组,那么f[]()就是函数的数组,因为数组是区别很大的,所以illegal


and:
int (* f [])(); /* this one legal. */ 这个就不一样了,表示的是一个指针数组,这个指针指向返回int的func


i really want know what's the usage of the second one.

thank you.

以上是我的问题……感谢各种回答啊!外国网站……真是神速……瞬间有个人帮我改了格式,瞬间有了回复~

http://cdecl.org/  这个是个好网站!

http://ideone.com/fzt1SX 这个是个好example~

#include <stdio.h>
int x = 0;
int a() { return x++ + 1; }
int b() { return x++ + 2; }
int c() { return x++ + 3; }

int main()
{
int (* abc[])() = {&a, &b, &c};
int i = 0,
l = sizeof(abc)/sizeof(abc[0]);
for (; i < l; i++) {
printf("Give me a %d for %d!\n", (*abc[i])(), i);
}
return 0;
}


http://stackoverflow.com/questions/13250777/whats-the-difference-between-int-f-and-int-f

突然觉得……怎么自己写的语言那么好理解……鸟语解释起来怎么就那么怪!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C pointers 语言