home *** CD-ROM | disk | FTP | other *** search
/ Beginning C++ Through Gam…rogramming (2nd Edition) / BCGP2E.ISO / source / chapter05 / global_reach.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-04-11  |  851 b   |  45 lines

  1. // Global Reach
  2. // Demonstrates global variables
  3.  
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. int glob = 10;  // global variable
  9.  
  10. void access_global();
  11. void hide_global();
  12. void change_global();
  13.  
  14. int main()
  15. {
  16.     cout << "In main() glob is: " << glob << "\n\n";
  17.     access_global();
  18.     
  19.     hide_global();
  20.     cout << "In main() glob is: " << glob << "\n\n";
  21.  
  22.     change_global();
  23.     cout << "In main() glob is: " << glob << "\n\n";
  24.  
  25.     return 0;
  26. }
  27.  
  28. void access_global()
  29. {
  30.     cout << "In access_global() glob is: " << glob << "\n\n";
  31. }
  32.  
  33. void hide_global()
  34. {
  35.     int glob = 0;  // hide global variable glob
  36.     cout << "In hide_global() glob is: " << glob << "\n\n";
  37. }
  38.  
  39. void change_global()
  40. {
  41.     glob = -10;  // change global variable glob
  42.     cout << "In change_global() glob is: " << glob << "\n\n";
  43. }
  44.  
  45.