Handout - scope


// Here is a skeleton of a program that we will use to illustrate
// the scope of identifiers (variables and function names)

// first, two globally-defined prototypes
// Since these prototypes are defined globally, the functions Block1
// and Block2 can be called from any place in the entire program

void Block1 (int a1, char& b2);
void Block2 (void);

// the next two variables are also defined globally
// Note that it is usually a BAD IDEA to define global variables

int a1;
char a2;

int main(){

  return 0;
}


void Block1 (int a1, char& b2){

  int c1;      // these local variables are known only
  int d2;      // inside the function Block1


  return;
}

void Block2 (void){

  int Block3 (int x);    // a local prototype
                         // Block3 can be called only from Block2

  int a1;                // variables local to Block2
  int b2;

  return;
}

int Block3 (int x){

  return x;
}