A scope is defined by its nearest set of braces. - C++ Language Basics

C++ examples for Language Basics:Variable

Description

A scope is defined by its nearest set of braces.

Demo Code

int main() {// ww w . ja  v  a 2  s. c o m
   int variable1;
   // variable1 visible here
   {
      // variable1 still visible here
      int variable2;
      // variable2 visible here
      {
         // variable1 & variable2 still visible here
         int variable3;
         // variable1, variable2 & variable3 visible here
      } // variable3 destroyed here
      // variable3 not available here
      // variable1 & variable2 still visible here
   } // variable2 destroyed here
   // variable3 & variable2 not available here
   // variable1 still visible here
} // variable1 destroyed here

Related Tutorials