The “right-left” rule is a completely regular rule for deciphering C declarations. It can also be useful in creating them.

Read the symbols as you encounter them in the declaration…

*   as "pointer to"          - always on the left side
[]  as "array of"            - always on the right side
()  as "function returning"  - always on the right side

How to apply the rule

STEP 1

Find the identifier. This is your starting point. Then say to yourself, “identifier is.” You’ve started your declaration.

STEP 2

Look at the symbols on the right of the identifier. If, say, you find () there, then you know that this is the declaration for a function. So you would then have “identifier is function returning”. Or if you found a [] there, you would say “identifier is array of”. Continue right until you run out of symbols OR hit a right parenthesis \\). (If you hit a left parenthesis \\(, that’s the beginning of a () symbol, even if there is stuff in between the parentheses. More on that below.)

STEP 3

Look at the symbols to the left of the identifier. If it is not one of our symbols above (say, something like “int”), just say it. Otherwise, translate it into English using that table above. Keep going left until you run out of symbols OR hit a left parenthesis \\(.

Now repeat steps 2 and 3 until you’ve formed your declaration.


Here are some examples:

int *p[];

First, find identifier:

int *p[];
     ^

“p is”

Now, move right until out of symbols or right parenthesis hit.

int *p[];
      ^^