S1
How to Read Each Declaration β Right Before Left
Start at p, look right first, then left β parentheses change the binding order
Reading Rule
The One Rule β Right Binds Before Left
Start at the name p. Look right β if you see
Putting
() or [] they bind before the * on the left. So int *p(char *a) β p sees (char *a) on its right first β p is a function. The * then applies to the return type β it returns int*.Putting
(*p) in parentheses breaks that rule β the parens force p to bond with * first β p is a pointer. Then (char *a) on the outside describes the function it points to.
Annotated reading β both declarations broken down token by token
int *p(char *a) β step by step
β Start at
β‘ Right:
β’ Left:
β£ Far left:
Result: p is a function(char*) β int*
pβ‘ Right:
(char *a) β p is a function taking char*β’ Left:
* β return type is a pointerβ£ Far left:
int β pointer to intResult: p is a function(char*) β int*
int (*p)(char *a) β step by step
β Start at
β‘ Parens:
β’ Right:
β£ Far left:
Result: p is a pointer to function(char*) β int
pβ‘ Parens:
(*p) β p is a pointerβ’ Right:
(char *a) β to a function taking char*β£ Far left:
int β function returns intResult: p is a pointer to function(char*) β int
The single visual test: Is there a
(*p) group? Yes β p is a pointer to a function. No β p is a function that returns a pointer. That one bracket pair is the only difference.