An Example of Bad Scope


/********************************
An example of bad scope in C++.
********************************/

#include < iostream.h >
const int MAX = 10;
int i;

void AnotherUse()
{
int buff[MAX];

    for (i = (MAX-1); i > -1; i--)
      {
      buff[i] = i;
      cout << i << " "; 
      } 
      cout << endl; 
    } 
void main() 
    { 
    int buff[MAX]; // buffer for integers 
    for(i=0; i < MAX; i++) 
      { 
      buff[i]=i; 
      cout << i << " "; 
      } 
    cout << endl; 
    AnotherUse(); 
    }

These pages were edited for style and content by Allan Caine, Laura Drever, Gorana Jankovic, Megan King, and Marie Lewis.

The original authors of these pages were Graeme Humphries, Chantal Laplante, Chris Mills, and Melvin Lenz.

Last Modified: Wednesday, June 7th 23:45:30
Copyright 2000 Department of Computer Science, University of Regina.


[CS Dept Home Page]