Block Scope of Variable :
- Block Scope is also called Local Scope
- It can be used only within a function or a block
- It is not visible outside the block
- Variables defined within local scope is called as Local variables
Definition :
Variable is said to have local scope / block scope if it is defined within function or local block
Live Example :
#include"stdio.h"
void message();
void main()
{
int num1 = 0 ; // Local to main
printf("%d ",num1);
message();
}
void message()
{
int num1 = 1 ; // Local to Function message
printf("%d ",num1);
}
Output :
- 0 1
Explanation :
- Program have two functions main and message
- In both functions we have declared variable 'num1'
- Both the variables have scope limited within the function body
- Local variables are printed as output.
- In main value 0 is assigned to num1
- In function message value 1 is assigned to num1

0 Comments:
Post a Comment
Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email