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: 442
        
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:
- *(ptr)
- (int)
- *(*ptr)(int)
- *(*(*ptr)(int))
Then,
- double **
- char c
Second example
unsigned **( * (*ptr) [5] ) (char const *,int *)
- *(ptr)
- [5]
- *(*ptr)[5]
- *(*(*ptr)[5])
- **(*(*ptr)[5])
How should I read them?
© Programmers or respective owner