Monday 9 April 2012

37).Write a Program to Explain The "Local Variable"

1).#include<conio.h>
   #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();

}


OUTPUT::  10
                  34




2)#include<conio.h>
#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;

}

OUTPUT::
Inner x : 77
Outer x: 10

No comments:

Post a Comment

Write a program which reads a set of integers into an integer array and then prints "YES"if all of them are same otherwise print "NO".

#include<stdio.h> int main() { int a[10],M=0,i,n; printf("enter a value for n\n"); scanf("%d",&n); fo...