Uploaded September 2026 | Updated November 2026, 2 days ago
Learn the difference between scope and lifetime of static and global variables in C programming.
In this tutorial, we clear up a common beginner confusion: if static and global variables exist for the entire execution of a program, does that mean they can be accessed everywhere in the source code?
We first understand the lifetime of static and global variables. These variables are created before main() starts executing and exist for the entire duration of the program. We compare this with a normal local variable, which exists only during the execution of its function.
Then we discuss variable scope. Scope tells us where a variable name is visible or accessible in the source code. A static variable declared inside a function has block scope, so its name can be accessed only within that block even though the variable exists for the entire program execution.
We also examine global variables and file scope. A global variable declared outside all functions is visible from its declaration to the end of the source file.
Finally, we see how an extern declaration can inform the compiler about a variable before its definition appears later in the source file.
Our Website
LearningLad.com
Social Media
Facebook facebook.com/LearningLad
Twitter twitter.com/LearningLadEdu
Instagram instagram.com/LearningLadOfficial
Learn the difference between scope and lifetime of static and global variables in C programming.
In this tutorial, we clear up a common beginner confusion: if static and global variables exist for the entire execution of a program, does that mean they can be accessed everywhere in the source code?
We first understand the lifetime of static and global variables. These variables are created before main() starts executing and exist for the entire duration of the program. We compare this with a normal local variable, which exists only during the execution of its function.
Then we discuss variable scope. Scope tells us where a variable name is visible or accessible in the source code. A static variable declared inside a function has block scope, so its name can be accessed only within that block even though the variable exists for the entire program execution.
We also examine global variables and file scope. A global variable declared outside all functions is visible from its declaration to the end of the source file.
Finally, we see how an extern declaration can inform the compiler about a variable before its definition appears later in the source file.
Our Website
LearningLad.com
Social Media
Facebook facebook.com/LearningLad
Twitter twitter.com/LearningLadEdu
Instagram instagram.com/LearningLadOfficial










