Scope of Variable in C
Scope of Variable is the part of the program where the identifier (or variable) may directly be accessible. In C, all identifiers are statically scoped. The variable is alive in its scope only and cannot be accessed outside it.
So there are two types of scopes depending on the region where variables are declared and used:
Local Variable
Variables that are declared inside a function or a block are called local variables and are said to have local scope. These local variables can only be used or access within the function or block in which these are declared. It is invalid outside it.
Global Variable
Variables that are defined outside of all the functions and are accessible throughout the program are global variables and are said to have global scope. Once declared, these can be accessed and modified by any function in the program. We can have the same name for a local and a global variable but the local variable gets priority inside a function.