Program to illustrate the scope of variables


     # include <iostream.h>
     int main( )
     {
    x=11;
    int x;                       //ERROR : This is not in the scope of x

    {
           x = 22;               //OK : This is in the scope of x
           y = 33;               //ERROR : This is not in the scope of y
           int y;
           x = 44;              //OK : This is in the scope of x
           y = 55;             //OK : This is in the scope of y
    }
    x = 66;                   //OK : This is in the scope of x
    y =77;                    //ERROR : This is not in the scope of y

         return 0;
      }

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|