Exercises
| 1. | If the program in Figure 5.24 is run, what will be displayed?
Figure 5.24. Exercise 1 (code\calc1.cpp)
#include <iostream>
using namespace std;
short i;
short Calc(short x, short y)
{
static short j = 0;
cout << "The value of j in Calc is: " << j << endl;
i ++;
j = x + y + j;
return j;
}
int main()
{
short j;
for (i = 0; i < 5; i ++)
{
j = Calc(i + 5, i * 2) + 7;
cout << "The value of j in main is: " << j << endl;
}
return 0;
}
|
|
Answers to exercises can be found at the end of the chapter.