Static is a key word ,which is used to indicate the variable as static means of deciding the variable scope and extend.
if the variable is declared as static variable then the life time of that variable is throughout the program .
Example:
#include<stdio.h>
int v = 20;
if the variable is declared as static variable then the life time of that variable is throughout the program .
Example:
#include<stdio.h>
int v = 20;
int main()
{
int x=0;
void funct1();
fun1();
printf("After first call \n");
fun2();
printf("After second call \n");
fun3();
printf("After third call \n");
}
void fun1()
{
static int y = 0;
int z = 10;
printf("value of y %d z %d",y,z);
y=y+10;
}
void funct1();
fun1();
printf("After first call \n");
fun2();
printf("After second call \n");
fun3();
printf("After third call \n");
}
void fun1()
{
static int y = 0;
int z = 10;
printf("value of y %d z %d",y,z);
y=y+10;
}
output:
value of y 0 z 10 After first call
value of y 10 z 10 After second call
value of y 20 z 10 After third call