Uploaded September 2026 | Updated November 2026, 5 days ago
Learn how static variables work in C programming and understand how they differ from normal local variables and global variables.
In this tutorial, we first see what happens to local variables when a function is called multiple times. Local variables are created during the function's execution and do not retain their values between function calls.
Then we use the static keyword to create a static variable and see how it retains its value between function calls. Using a simple count example, we call the same function multiple times and observe how the static variable keeps its modified value.
You will also learn about the lifetime and scope of static variables. Static variables exist for the entire duration of the program, but a static variable declared inside a function is visible only within that function. We also see that an uninitialized static variable gets a default value of zero.
Finally, we discuss static global variables. You will learn how using the static keyword with a global variable restricts its visibility to the source file where it is defined and prevents other source files from accessing it using extern. This concept is also introduced as internal linkage.
Our Website
LearningLad.com
Social Media
Facebook facebook.com/LearningLad
Twitter twitter.com/LearningLadEdu
Instagram instagram.com/LearningLadOfficial
Learn how static variables work in C programming and understand how they differ from normal local variables and global variables.
In this tutorial, we first see what happens to local variables when a function is called multiple times. Local variables are created during the function's execution and do not retain their values between function calls.
Then we use the static keyword to create a static variable and see how it retains its value between function calls. Using a simple count example, we call the same function multiple times and observe how the static variable keeps its modified value.
You will also learn about the lifetime and scope of static variables. Static variables exist for the entire duration of the program, but a static variable declared inside a function is visible only within that function. We also see that an uninitialized static variable gets a default value of zero.
Finally, we discuss static global variables. You will learn how using the static keyword with a global variable restricts its visibility to the source file where it is defined and prevents other source files from accessing it using extern. This concept is also introduced as internal linkage.
Our Website
LearningLad.com
Social Media
Facebook facebook.com/LearningLad
Twitter twitter.com/LearningLadEdu
Instagram instagram.com/LearningLadOfficial










