< C++ Programming < Scope < Examples
// Complicated Scope Program
#include <iostream>
  
using namespace std;  /* outermost level of scope starts here */

int i;

int main(){               /* next level of scope starts here */
  int i;
  i = 5;

  {                   /* next level of scope starts here */
    int j,i;
    j = 1;
    i = 0;
  
    {                 /* innermost level of scope of this program starts here */
      int k, i;
      i = -1;
      j = 6;
      k = 2;
    }                 /* innermost level of scope of this program ends here */

    cout << j << ' ';
  }                   /* next level of scope ends here */

  cout << i << endl;
  return 0;
}                     /* next and outermost levels of scope end here */
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.