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’re not going to use them anyway? Typically, you pass NULL as an address to tell the function “I don’t 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 cartesianToPolar():
void cartesianToPolar(float x, float y, double *rPtr, double *thetaPtr) { // Is rPtr non-NULL? if (rPtr) { // Store the radius in the supplied address *rPtr = sqrt(x * x + y * y); } // Is thetaPtr NULL? if (!thetaPtr) { // Skip the rest of the function return; } // Calculate theta float theta; if (x == 0.0) { if (y == 0.0) { theta = 0.0; // technically considered undefined } else if (y > 0) { theta = M_PI_2; } else { theta = - M_PI_2; } } else { ...