Tuesday, 31 December 2013

Example of Local Variable Using C++

1st example:::::::---------
#include<iostream.h>
  void function1()
 {
  int x;  
  x=10;
  cout<<"\n" <<x;
 }
void function2()
{
int x=34;
cout<<"\n" <<x;
}
void main()
{
       clrscr();
       function1();
       function2();

}

2nd example:::::::---------
#include<iostream.h>
void main()
{
   clrscr();
   int x =10        
   if(x==10)
    {
         int x; /*this x hides outer x*/
         x=77;
        cout<<"Inner x : " <<x;
     }
  cout<<"\n Outer x : "  <<x;
}

No comments:

Post a Comment