Variable scope example

De Software testing
Ir para: navegação, pesquisa
{           // begin outer block
   int x;   // x is defined as an integer within this outer block 
   ...;     // x can be accessed here 
   {        // begin inner block
      int y;// y is defined within this inner block 
      ...;  // both x and y can be accessed here 
   }        // y is automatically destroyed at the end of this block 
   ...;     // x can still be accessed, but y is gone
}           // x is automatically destroyed