August 2002
Beginner
1122 pages
22h 1m
English
| 1. | If you got this one right, congratulations! It's just filled with tricks, but they're all things that you might run into in a real (although poorly written) program. Here's the answer:
The value of j in Calc is: 0 The value of j in main is: 12 The value of j in Calc is: 5 The value of j in main is: 23 The value of j in Calc is: 16 The value of j in main is: 40 The first question is why there are only three values displayed by each output statement. The for loop that calls the Calc routine and displays the results should execute 5 times, shouldn't it? This is the first trick. Since i is a global variable, the statement i ++; in the Calc function affects its value. Therefore, i starts out at 0 in the main function, as usual, ... |
Read now
Unlock full access