H.A.6.1 o scope

SCOPE AND VALUE PARAMETERS

 

 

 

// scope.cpp

 

#include <iostream.h>

 

const int NUM = 21;       // a global constant

 

 

void one (int);                  // function prototypes do not need identifiers

void two (int, int);           // but they do need ;'s at the end of each line

void three ();

 

main()

{

       int a = 2, b = 5;

      

       one (a);

       two (a,b);

       cout << a << "  " << b << endl;

       three ();

       cout << a << endl;

       return 0;

}

 

void one (int s)           // notice lack of ;

{

       cout << s << endl;

       s *= 3;

       cout << s << endl;

       cout << NUM << endl;         // use of a global constant

}

 

void two (int a, int b)            // a and b are local identifiers

{

       a += 2;

       b *= a;

       cout << a << endl;

       cout << b << endl;

}

 

void three()

{

       int a = 7;

      

       cout << a << endl;

}

 

Run Output:

 

2

6

21

4

20

2   5

7

2