Source of scope4.cpp


  1: //scope4.cpp
  2: //A nonsense program to test your understanding
  3: //of variable scope and lifetime.

  5: #include <iostream>
  6: using namespace std;

  8: void P(int& i, int& j)
  9: {
 10:     i = 3*i;
 11:     cout << i << j << endl;
 12:     j = i + j;
 13:     cout << i << j << endl;
 14: }

 16: int i, j; //Global variables

 18: int main()
 19: {
 20:     cout << endl;
 21:     i = 2;
 22:     j = 3;
 23:     cout << i << j << endl;
 24:     P(j, j);
 25:     cout << i << j << endl;
 26: }