C Pointers Made Easy
For newcomers to C, whether you are new to programming in general or just are used to living in HLL land, pointers can get confusing fast. Here is one trick I used to keep my code readable when I was getting my C sea-legs.
Prepend ‘p_’ to pointer variables and ‘pp_’ to pointers to pointers
To make C pointer code more readable, you can add some mnemonics to your variable names like so:
’*p_’ cancels out
Having the ‘p_’ in our pointer names helps us later when we want to derefence something. We can easily read what is going on without having to backtrack or try to keep it all in our own human working memory. Like so:
Assignments are less error-prone too
This also comes in super handy when doing assignments because you know you are assigning things at the correct level: