Friday, March 4, 2011

User-Defined Functions

Write a program to illustrate the properties of a static variable.

#include <stdio.h>
void stat(void);
void main ()
   {
 int i;
 for(i=1; i<=3; i++)
 stat( );
 getch();
   }
void stat(void)
{
   static int x = 0;
   x = x+1;
   printf("x = %d\n", x);
}

OUTPUT
x = 1
x = 2
x = 3

No comments:

Post a Comment