Static variables have a property of preserving their value even after they are
out of their scope!Hence, static variables preserve their previous value in
their previous scope and are not initialized again in the new scope.
static data_type var_name = var_value;
Following are some interesting facts about static variables in C.
1) A static int variable remains in memory while the program is running. A normal or auto variable is destroyed when a function call where the variable was declared is over.
For example, we can use static int to count number of times a function is
called, but an auto variable can't be sued for this purpose.
3) Static variables (like global variables) are initialized as 0 if not initialized explicitly. For example in the below program, the value of x is printed as 0, while the value of y is something garbage. See this for more details.