Last Updated: February 25, 2016
·
622
· ranjeet-kumar

How to declare a pointer to a function?

int * ptrInteger; /We have put a * operator between int
and ptrInteger to create a pointer.
/

int * foo(int); //This is wrong
Bcoz..C operator precedence also plays role here ..so in this case, operator () will take priority over operator *. And the above declaration will mean – a function foo with one argument of int type and return value of int * i.e. integer pointer.

we have to bind operator * with foo somehow. And for this, we would change the default precedence of C operators using () operator.
int (*foo)(int); //Correct