Scope of variables | Practically representation of scope of variables



Details:
            It is difficult to understand the scope of variable as from bookish material. I write a program that easily elaborate the concept of scope. Here we discuss global variable and local variable. You just copy it and paste on your compiler and then see what is the difference....


Instructions: 
             Remember that the compiler is  translated program as a whole program. The control of the compiler is starts from up and terminate at the end of the program. So keep my words and see the magically behavior of compiler towards same name variable "Ali".


Source codes:

// This is written by "Syed Ali Haider"
// Student of Havjery University
// Don't remove these line for legal use
// Upload on Let's programming by (CEO)
// For contact
// key_to_programming@yahoo.com
# include <iostream>
using namespace std;

int ali=5; // a global variable ,this is not used even in any of the statement

void main (void)
{
       int ali=100; // variable of outer block of codes

       for (int i=1; i<=10; i++)
       {
              // here I call the variable of "Ali" and before the new variable declare the outer variable is being used
              cout<<"This is the variable of outer block of code: "<<ali<<endl<<endl;

              int ali=10; // variable for inner block of codes

              // here I call the varible of "Ali" after new variable declare , the inner variable is being used
              cout<<"This is the variable of inner block of code: "<<ali<<endl<<endl;
       }
// This is written by "Syed Ali Haider"
// Student of Havjery University
// Don't remove these line for legal use
// Upload on Let's programming by (CEO)
// For contact
// key_to_programming@yahoo.com
}

Comments

Popular posts from this blog

Umbrella activities in Software Engineering

Operating System | Best Definition of Opetating System