1: //scope2.cpp
2: //Illustrates global function scope and "prototype scope"
4: #include <iostream>
5: using namespace std;
7: #include "utilities.h"
8: using Scobey::Pause;
10: int i = 1;
11: void DoIt(int& i); //DoIt has global (file) scope; i has "prototype scope"
13: int main()
14: {
15: int i = 3;
17: DoIt(i);
18: cout << endl << i << endl;
19: Pause(0, "", 1);
20: {
21: DoIt(i);
22: cout << i << endl;
23: Pause(0, "", 2);
25: i = 5;
26: DoIt(i);
27: cout << i << endl;
28: Pause(0, "", 3);
30: int i = 7;
31: DoIt(i);
32: cout << i << endl;
33: Pause(0, "", 4);
34: }
35: DoIt(i);
36: cout << i << endl;
37: Pause(0, "", 5);
38: }
40: void DoIt(int& j)
41: //Note that we don't have to use i as the parameter name here.
42: {
43: j *= j;
44: }
46: /*
47: Question:
48: What values are output?
50: Answer:
51: 9 81 25 49 625
52: */