Local/Global Variable

Local variable

The local variables are defined within the body of the function are called local variable. These variables are created when the function are begin and destroyed when the function is end. For example:
void func (void)
{
int a,b;
...........
...........
}
or
void func (void)
{
int a=3,b=5;
...........
}
a and b or a=3 and b=5 are local variable which are defined within body of the func().

Global variable

The variables are defined outside of the function are called global variable. All function in a program can access and modify global variable. Used to declare global variable for many function in the program. Global variable is automatically initialized to zero ( 0 ) at the time of declaration. For example:
int a,b=4;
int main(void)
{
..............
.............
}
output: inside main(): a=0 b=4 a and b are global variable which are defined outside main(). The variable a automatically initialized 0.

Static variable

The static variable are declared by writing Static keyword in front of declaration. If static variable is not initialized the it is automatically initialized zero ( 0 ). For example:
Syntax: static type var_name
void func (void) { int a=4; static int b=4; ………….. ………….. } a=4 is local variable and b=4 is static variable.