What is a static variable?

C Programming Language >   Variable in C Language >   Variable types and Scope in C  

Short Question

960


Answer:

A static local variables retains its value between the function call and the default value is 0. The following function will print 1 2 3 if called thrice.

void f() { 
static int i;
++i;
printf(“%d “,i);
}

If a global variable is static then its visibility is limited to the same source code.


This Particular section is dedicated to Question & Answer only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.




Join Our telegram group to ask Questions

Click below button to join our groups.