什么呢,行int *(*(X [3])())[5];用C呢? [英] what does the line int *(*(x[3])())[5]; do in C?
问题描述
这是我第一次问上堆栈溢出的问题,所以请下跌自由地告诉我,如果我做错了什么,或不够具体。
我一直用C约4现在微控制器编程。几天前我在一家电子参加比赛。其中的许多问题是究竟是什么C $ C $克莱恩
This is my first time asking a question on Stack Overflow, so please fell free to tell me if I did anything wrong or not specific enough. I've been programming microcontrollers in C for about 4 now. Some days ago I took part in an Electronics Competition. One of the many questions was what exactly the C codeline
int *(*(x[3])())[5];
一样。这是该行,我记得。这可能是一个架在一个其他位置,但我认为这是行了。
does. This is the line as I remember it. It is possible that a bracket was at an other location, but I think this was the line.
我的猜测是,x是一个我们把第四个元素,并取消对它的引用functionpointers的数组。然后,这个函数时没有移交参数执行。的返回值似乎是一个指针的指针数组,其中我们解引用一次,以获得第一个元件的地址。然后,我们选择数组的元素第六。我不知道是什么int是因为虽然...
My guess is that x is an array of functionpointers of which we take the fourth element and dereference it. This function is then executed without handing over parameters. The returnvalue seems to be a pointer to a pointer an array of which we dereference once in order to get the address of the first element. We then choose the 6th element of that array. I have no idea what the int is for though...
非常感谢您回答我的问题,并有一个愉快的一天。
Thank you very much for answering my question and have a nice day.
推荐答案
阅读毛茸茸的声明,这样是出去找最左边的标识符和工作的方式,记住以下precedence规则的方式:
The way to read hairy declarations like this is to find the leftmost identifier and work your way out, remembering the following precedence rules:
*a[n] -- a is an array of pointer
(*a)[n] -- a is a pointer to an array
*f() -- f is a function returning a pointer
(*f)() -- f is a pointer to a function
应用这些规则,我们得到
Applying these rules, we get
x -- x is a
x[3] -- 3-element array of
(x[3])() -- function returning
*(x[3])() -- pointer to
(*(x[3])())[5] -- 5 element array of
*(*(x[3])())[5] -- pointer to
int *(*(x[3])())[5]; -- int
由于写的,这个声明是无效的;你不能有功能类型的阵列。我想这应该是像
As written, this declaration isn't valid; you can't have an array of function type. I imagine it was supposed to be something like
int *(*(*x[3])())[5];
其中, X
是一个数组的指针的久违指针的指针为int数组功能。
where x
is an array of pointers to functions returning pointers to arrays of pointers to int.
这篇关于什么呢,行int *(*(X [3])())[5];用C呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!