November 2013
Beginner
325 pages
9h 47m
English
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():
void metersToFeetAndInches(double meters, unsigned int *ftPtr, double *inPtr)
{
double rawFeet = meters * 3.281;
unsigned int feet = (unsigned int)floor(rawFeet);
// Store the number of feet at the supplied address
if (ftPtr) { printf("Storing %u to ...Read now
Unlock full access