Avoid dereferencing NULL

Sometimes a function can supply many values by reference, but you may only care about some of them. How do you avoid declaring these variables and passing their addresses when you are not going to use them anyway? Typically, you pass NULL as an address to tell the function I do not need this particular value.

This means that you should always check to make sure the pointers are non-NULL before you dereference them. Add these checks in metersToFeetAndInches():

v​o​i​d​ ​m​e​t​e​r​s​T​o​F​e​e​t​A​n​d​I​n​c​h​e​s​(​d​o​u​b​l​e​ ​m​e​t​e​r​s​,​ ​u​n​s​i​g​n​e​d​ ​i​n​t​ ​*​f​t​P​t​r​,​ ​d​o​u​b​l​e​ ​*​i​n​P​t​r​)​ {​ ​ ​ ​ ​d​o​u​b​l​e​ ​r​a​w​F​e​e​t​ ​=​ ​m​e​t​e​r​s​ ​*​ ​3​.​2​8​1​;​ ​ ​ ​ ​u​n​s​i​g​n​e​d​ ...

Get Objective-C Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.