0

So I have the following expression

int *(*table())[30];

In my opinion table() return a value which points to the beginning of an array of pointers which each element points to an integer.

What do you think?

Thanks.

0

1 Answer 1

5

You're correct. According to cdecl

int *(*table())[30];

declare table as function returning pointer to array 30 of pointer to int

See also the clockwise/spiral or right-left rules for help understanding C expressions (and see comments below for some points in favour of the latter).

8
  • 1
    I wouldn't recommend spiral rule. Because it is 1) overcomplicated and 2) wrong (try to parse int a[4][5] for example). There's more simple and reliable rule: ieng9.ucsd.edu/~cs30x/rt_lt.rule.html
    – kotlomoy
    May 25, 2013 at 16:35
  • 1
    @kotlomoy you need to insert the implicit parentheses for the spiral rule, int (a[4])[5];, then it works, as far as I know. May 25, 2013 at 17:59
  • 2
    Rather the contrary, if you have to do something unusual to use it, that's a point against using it, I'd think. May 25, 2013 at 18:25
  • 1
    @kotlomoy Thanks for your comments. I've added a link to the right-left rule to my answer.
    – simonc
    May 25, 2013 at 18:44
  • 1
    @kotlomoy The whole point of precedence is to make some parentheses implicit. So where I said "implicit parentheses", I could have spoken of precedence. But "You can use the spiral rule if you deviate from it when precedence demands it." doesn't sound as snappy as "It works when you insert the implicit parentheses.", so I prefer to use the latter to make a pun. May 25, 2013 at 18:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.