Storage class in C programming defines scope and lifetime of a variable and function. At the time of variable declaration we define both data type as well as storage class of a variable.
Scope Rules
Global variables in C
Global variables are variables declared outside a function. Unlike local variables and static variables, a global variable is not declared inside a function.
Static variables in C
Static variables are declared with static
keyword. Static variables have an essential property of preserving its value across various function calls. Unlike local variables, static variables are not allocated on C stack. Rather, they get their memory in data segment of the program.
Local variables in C
Quick links
Local variables are variables declared within a function or more specifically say within a block.
Block is a sequence of statements grouped together inside a pair of curly braces {
and }
. Since the first day of programming, you have been using blocks. For example – if…else block, loop block, function block etc.