C Variable Scope

Scope of variable means the existence of variable within block or region in which variable can be accessed.  Variable accessing scopes are local and global scopes.

Local Variable: A variable declared between a block or function is known as local variable.Local variables are accessed through local scope. They can be accessed through the function and block in which they are declared,other functions cannot access these variables.

Global Variable: A variable declared outside of all function is known as global variable.Global variables are accessed through all functions.

 

Examples :

Local Variable :

Here a,b,c are local variables to the main function

Global Variable:

a is local to foo.

b is local to main.

g is a global variable.