Functions on Call
When we use functions in C, a very specific sequence of events
Each of the
That is, we perform any calculations that are necessary to get a single
value for that argument.
The function is
with the arguments
Calling a function temporarily
transfers the control of the program to that function.
By passing of arguments we mean that the values which were determined for the
arguments in Step 1, are made available to function being called.
The function executes the statements in it's
The called function then
to the calling function.
(We will often refer to the called function as the
calling function as the
The callee may compute a
which is then sent back
to the caller.
By way of example, let us look at the call to the function
sqrt(square(side_a) + square(side_b))
that we saw in
Here the function
(which computes square roots) has one
argument, the expression:
square(side_a) + square(side_b)
When we call
, we first evaluate this expression.
In order to evaluate it, we must make two function calls and add the
For the first of these calls, we pass the value of the variable
to the function
Suppose that the value of
Then after we've called
before calling it on
it's as if the expression were
16.0 + square(side_b)
Then we call square on
is 3.0, then we now have the expression:
16.0 + 9.0
which evaluates to 25.0 which is the value passed to
It then returns with the value 5.0.
So our return statement is as if we had typed:
and 25.0 becomes the value of the call:
is 4.0 and