What is the part to the right of a function in parenthesis? What does it actually mean/do? Why is it necessary?
Some examples from the book:
• void showCookTimeForTurkey (int pounds) …p. 34 makes perfect sense
• void singSongFor(int numberOfBottles) …p.36 now it references something established by coder
• float fahrenheitFromCelcius(float cel) …p.40 even though the return is “fahr”
• from CHALLENGE: float remainingAngle (angleA, angleB) …p42 even though that naming is used in int main
[quote]What is the part to the right of a function in parenthesis? What does it actually mean/do? Why is it necessary?
[/quote]
That’s where you declare the parameters in the parameter list.
Every function has a return-value type, and a parameter list between a pair of parentheses.
Here is the syntax for function declaration:
ReturnValueTypeFunctionName (ParameterList)
For example, declare some functions:
void Foo (); // No return value, no parameter list
unsigned long SumNumbersTo (const unsigned long);
unsigned long BiggerOf (const unsigned long, const unsigned long);
NSString * RandomStringWithMaxLength (const unsigned long);
Define some functions:
void Foo ()
{
printf ("Hello, I am %s\n", __func__);
}
unsigned long SumNumbersTo (const unsigned long N)
{
if (N == 0) {
return 0;
}
else {
return N + SumNumbersTo (N - 1);
}
}
unsigned long BiggerOf (const unsigned long A, const unsigned long B)
{
return A >= B ? A : B;
}
specifically: float freezeInF = fahrenheitFromCelsius(freezeInC) - i get what’s going on, i just don’t get why. I understand here that we’re calling a function and in doing so we’re passing the value of freezeInC. It’s obvious to me the function is using the value of freezeInC, 0, and assigning that to “cel” - but how does that work? Is it because the parameters are in the same place?