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.

Get C++: A Dialog Programming with the C++ Standard Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.