Search This Blog

Friday, 14 June 2013

understanding life time and scope

#include <iostream.h>

void f ();

int i = 0;

void main () { 
  cout << i << endl;  
  int i = 1;
  cout << i << endl;
  { 
    int i = 2;
    cout << i << endl;
    { 
      int i = 3;
      cout << i << endl;
      { 
 int i = 4;
 cout << i << endl;
      }
      cout << i << endl;
    }
    cout << i << endl;
  }
  cout << i << endl;
  f(); f(); f();
}

void f () {
  cout << i << endl;
  static int i = 5;
  cout << i++ << endl;
}

No comments:

Post a Comment