Scope of Variable :
#include"stdio.h"
void message();
void main()
{
int num1 = 6 ;
printf("%d",num1);
message();
}
void message()
{
printf("%d",num1);
}
Output of Above Program :
- Compile Error : Variable num1 is visible only within main function , It cannot be accessed by other function
Definition of Scope of Variable :
Scope of variable is defined as Region or Part of Program in which the variable is visible / accessed / valid .
Rules of Scope of Variable :
- Local Variables are accessed / Visible only in Local Block
- Global variables can be explained from anywhere in program
- Priority is Given to Local variable if the two variables are declared with same name,type but in different blocks/functions

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