SOURCE FILE: EX0306.CPP


// Example 3.6. Example of functions using a global variable      
   
#include <iostream.h>
   
int i;                  // global 
   
int main(void)   
{   
   void modify_i(void);   
   
   i = 1;               // global i is assigned 1 
   
   cout << "Before calling modify_i, i equals " << i << endl;   
   modify_i();   
   cout << "After  calling modify_i, i equals " << i << endl;   
   
   return 0;
}   
   
//   
// Function modifies global i   
// Pre:  i is a global integer variable.   
// Post: Global variable i has been assigned 3.   
//    
   
void modify_i(void)   
{   
   i = 3;               // global i is assigned 3 
}