Scope of variable in C
Scope is the lifetime of variables. Variables have two types depending upon scope.
- Local variable
- Global variable
a. Local variable
Variable declared inside a function body is called local variable. It can exist only within the function in which it is declared.
b. Global variable
Variable declared before all function definitions is known as global variable. The value of global variable exists throughout the program. Changes made to them have effect on entire .
|Program for local and global variables.|
int a=10; /*global variable*/
printf(“\nGlobal variable in show() %d”,a);
int k=50; /*Local variable*/
printf(“Local variable in main=%d”,k);
|Local variable in main=50|
Global variable in main() =10
Global variable in function a=11
Global variable in main() a=12
Best Books of C