Function argument


#1

float freezeInC = 0;
float freezeInF = fahrenheitFromCelsius(freezeInC);

At this point fahrenheitFromCelsius function should have the value 32, and seems to have it.
Then, what does (freezeInC) actually do, since its value is 0 ?

If my question seems stupid I must say that I have done some programming a very long time ago, in Basic and Cobol !


#2

[quote]float freezeInC = 0; float freezeInF = fahrenheitFromCelsius (freezeInC);
At this point fahrenheitFromCelsius function should have the value 32, and seems to have it.
Then, what does (freezeInC) actually do, since its value is 0 ?[/quote]
freezeInC is the argument you are passing to the function; the function will use the value of the argument to do its work.


#3

Thank you for your answer. But I’m afraid I still don’t understand.
If the fonction uses the argument freezeInF then its value should become 0 and no longer be 32.


#4

The example in the book looks like this:

float FahrenheitFromCelsius (const float celsius)
{
   float result = 1.8 * celsius + 32;
   return result;
}

The function uses the value of whatever is passed as argument to compute the result it returns.

For example, if you invoke the function like this:

float freezeInC = 10;
float freezeInF = fahrenheitFromCelsius (freezeInC);

It will return the value of the expression 1.8 * 10 + 32.


#5

I think I get it. Thank you for your patience ibex