The program reads an integer into a
variable called favorite. The program then uses the integer in a message.
Remember, when the program asks for an input you must first click in the black
program window before you type the input.
For example, you can click in the program's window and type 42. Then the program will write:
Yes, 42 is a fine number.
Compile the program, then use
the debugger to put a breakpoint on the first line of the program.
Then execute the program until the message asking for a number
is printed. Use the number 42 as the input, and continue
executing until the the highlighted line is the function call:
increment_and_print(favorite);
Now, before we actually execute the increment_and_print function,
you should put watches on the favorite variable. It should have a
value of 42. Then step into the function.
When you step into the function, the debugger will move to the start of the
increment_and_print function, and favorite is no longer shown because
it is not available in the function.
From inside the function,
the variable favorite
is not available (since it is a local
variable of the main program, and only available when we are actually
inside the main program).
However, you can now put a watch on the variable i.
The variable favorite provided the initial value (42) for i, but there is no
longer any connection between i and favorite variables. We can execute the rest of
the function, changing i to 43, and the value of favorite remains unchanged.
Do this now, executing statements until you get back to the main program. You should
have seen i change to 43, and when you got back to the main program favorite
is still 42. This is the way that an ordinary argument works: The actual
argument merely provides the starting value for the formal argument of the
function.
Continue to execute statements until the program ends.