Page 38, return value to freezeInC?


"See how we took the return value of fahrenheitFromCelsius() and assigned it to the freezeInF variable type float? "

Not really…

Sorry to be a dolt, but where does return fahr; send or ‘return’ its value (of 32) to, exactly? I’m having a hard time seeing how it gets to freezeInF. Does it get placed in float freezeInF? If so, why not float freezeInC? I’m having difficulty seeing the logical path here…

Thanks in advance, as a green noob I am really enjoying the book!


So, functions can return a value. For example, the sqrt() function returns the square root of whatever you pass it as an argument:

float x = sqrt(9); // Now x is 3.0
You’ve created a function that returns a number, and you are immediately storing that number in the variable freezeInF:

float freezeInF = fahrenheitFromCelsius(0);




I think I see it now. I placed brake points all along the program, and the journey starts at main(), specifically [float freezeInC]. Then goes to [float freezeInF], where it calls the function [fahrenheitFromCelsius()]. We then see it jumping up to [float fahr = cel * 1.8 + 32;] under the [float faherenheitFromCelsius()] function. Down again to the [printf()] function, then on to [return fahr;], which has “returned” the value (now 32) to [faherenheitFromCelsius()], which is assigned to [freezeInF], which is now therefore the value of 32.

Yes, I know I am really over thinking at this point, but I just want to be really sure of what’s going on.

thanks again for your response, and sorry again for being so thick…