(Last Revision -- 03/12/00)

Scope Example Adapted from Shiflet, pp. 127-128

/* Exercise program to illustrate scope. */

#include <iostream.h>

int desultory (int zebra) ;
int yak ;

int main (void)
{
  int xero = 3;
  yak = xero ;
  
  cout << endl ;
  cout << "In main *before* calling function desultory, xero = " ;
  cout << xero << ", and " << endl  ;
  cout << "yak = "  << yak << endl << endl;

  xero = desultory(4) ;  /* note actual parameter is a constant */

  cout << "In main *after* calling function desultory, xero = " ;
  cout << xero << ", and " << endl  ;
  cout << "yak = "  << yak << endl << endl;

  return 0 ;
} 

/* Function called by main */

int desultory(int zinnia)
{
  int xero = 10 ;
  
  cout << "In function desultory, xero = " << xero << "," << endl ;
  cout << "yak = "  << yak << ", and"<< endl ;
  cout << "zinnia = "  << zinnia << endl << endl;

  yak = zinnia ;

  return 50 ;

}