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