Monday 9 April 2012

38).Write a program to differentiate "Local variable" and "static variable"

#include<conio.h>
#include<iostream.h>
void function()
{
  int j=10;
  cout<<j<<"\n" ;
  j++;
}
void main()
{
       clrscr();
     int i=10;
     for(i=0;i<10;i++)

     {

       function();
     }

}

OUTPUT::

The following program prints the number 10 ten times.



#include<conio.h>
#include<iostream.h>
void function()
{
static int j=10;
 cout<<j<<"\n" ;
 j++;
}
void main()
{
       clrscr();
     int i=10;
     for(i=0;i<10;i++)

     {

       function();
     }

}


OUTPUT::
10
11
12
13
14
15
16
17
18
19

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...