Monday 9 April 2012

34).Explain The Difference Between "static int variable" And "int variable"

#include<conio.h>
#include<iostream.h>
void function1()
{

  int x1=0;
  cout<<"The value of x1= \n" <<x1<<"\n";
  x1=x1+1;
}

void function2()
{

  static  int x2=0;
  cout<<"The value of x2= \n" <<x2<<"\n";
  x2=x2+1;
}
void main()
{
     clrscr();
  function1();
  function1();
  function1();
  function2();
  function2();
  function2();
   getch();
}


OUTPUT::
The value of x1= 0
The value of x1=0
The value of x1=0
The value of x2=0
The value of x2=1
The value of x2=2

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