Local, Global and Static variable
Local variable:
Variables that are defined with in a body of function or block. The local
variables can be used only in that function or block in which they are declared.
Same variables may be used in different functions such as
function()
{
int a,b;
function 1();
}
function2 ()
{
int a=0;
b=20;
}
Global variable:
The variables that are defined outside of the function is called global variable. All
functions in the program can access and modify global variables. Global variables
are automatically initialized at the time of initialization.
Example:
#include
void function(void);
void function1(void);
void function2(void);
int a, b=20;
void main()
{
printf(“inside main a=%d,b=%d \n”,a,b);
function();
function1();
function2();
}
function()
{
Prinf(“inside function a=%d,b=%d\n”,a,b);
}
function 1()
{