What is Global and Local variables

Global and Local Variables in C :

Local Variable:

Variables which are declared within a function or block are Local variables. These variables are accessed by functions or block in which they are declared.

Example:

Variable c in local variable.

 

Global Variable:

Variables which are declared outside the all functions are Global variables. These variables are accessed by all functions.

Example:

Variable a is accessible by both main and foo function.

Output :

10 11

 

%d bloggers like this: