
20 Intermediate C Programming
• The arguments and the return location together form the frame of the called function.
• When a function is called, the line number after this call is pushed onto the call stack.
This line number is the “return location” (RL). This is the place from which the
program will continue after the called function finishes (i.e., returns).
• If the same function is called from multiple lines, then each call has a corresponding
return location (the line after each function call).
• When a function finishes, the program continues from the line number stored at the
top of the call stack. The top of the call stack is then popped.
Note that the caller (f2) is not obliged to store the return value of the callee (f1), and
line 9 in the example above can be written as:
f1 (7, 2) ;9
In this case, function f1 is called but the returned value is discarded. Since there is no need
to store the return value, the value address is not pushed onto the call stack.
The keyword return can be used for two different purposes:
• If void is in front of the function’s name, the function does not return any value. The
word return stops the function and the program continues from the return location
in the caller.
• If the function is not void, the word return assigns a value to the variable given by
the value address in the call stack.
Please remember that if a function executes a return statement, anything after the
return is ignored and will not be executed. Executing a return statement stops the func-
tion, and its frame is popped from the call stack. The program then continues from the
return location.
2.3.5 Arrays
The following example creates an array of five elements. Each element contains one
integer, which will be uninitialized.
int arr [5];1
Symbol Address Value
arr[4] 104 garbage
arr[3] 103 garbage
arr[2] 102 garbage
arr[1] 101 garbage
arr[0] 100 garbage
If an array has five elements, the valid indexes are 0, 1, 2, 3, and 4. The first index is
0, not 1; the last index is 4, not 5. The array is said to be “zero indexed”. In general, if an
array has n elements, the valid indexes are 0, 1, 2, ..., n − 1. Please remember that n is
not a valid index. This is a common mistake among students.
Programmers have no control over addresses and this is still true for arrays. The ad-
dresses of an array’s elements are, however, always contiguous. Suppose i < j < k and all
of them are valid indexes for an array called arr. Then the address of arr[j] is between
the addresses of arr[i] and arr[k]. If an array’s elements are not initialized (like in the
example above), then the values are garbage.
The following example illustrates C’s facility to initialize arrays:
int arr [5] = { -31 , 52 , 65 , 49 , -18};1