How is precedence determined in C pointers?

Posted by ankur.trapasiya on Programmers See other posts from Programmers or by ankur.trapasiya
Published on 2011-11-21T20:20:23Z Indexed on 2011/11/22 2:09 UTC
Read the original article Hit count: 342

Filed under:
|

I've come across two pointer declarations that I'm having trouble understanding. My understanding of precedence rules goes something like this:

Operator             Precedence             Associativity
(), [ ]                  1                  Left to Right
*, identifier            2                  Right to Left
Data type                3

But even given this, I can't seem to figure out how to evaluate the following examples correctly:

First example

float * (* (*ptr)(int))(double **,char c)

My evaluation:

  1. *(ptr)
  2. (int)
  3. *(*ptr)(int)
  4. *(*(*ptr)(int))

Then,

  1. double **
  2. char c

Second example

unsigned **( * (*ptr) [5] ) (char const *,int *)
  1. *(ptr)
  2. [5]
  3. *(*ptr)[5]
  4. *(*(*ptr)[5])
  5. **(*(*ptr)[5])

How should I read them?

© Programmers or respective owner

Related posts about c

    Related posts about pointers