Define Scope Rules of C program - Computer Programming?
The fundamental rule of scope is that identifiers are accessible only within the block in which they are declared and they are unknown outside the boundaries of that block.
The scope of the variable determines over what part of the program and a variable is actually available for use.
Let us see a simple instance
main()
{
int a=2; /*outer .block a*/
printf("%d\n",a); /* 2 is printed*/
{
int a=5; /*inner block a*/
printf("%d\n",a); /* 5 is printed*/
} /*back to the outer block*/
printf("%d\n",a); /* 2 is printed*/
}
Every block introduces its own nomenclature. A name of outer block is valid until an inner block redefines it. If redefined the outer block name is masked or hidden from the inner block.