Write a program that illustrates the scope rules in blocks.

C Programming Language / Function in C Language

855

Program:

#include <stdio.h>
int main()
{
	int x= 3; /* variable declaration in outer block */
	printf("\n in outer block x = %d before executing inner block ", x);
	{
		int x= 45; /* variable declaration in inner block */
		printf("\n in inner block x = %d", x);
	}
	printf("\n in outer block x = %d after executing inner block ", x);
	return 0;
}
 

Output:

 in outer block x = 3 before executing inner block
 in inner block x = 45
 in outer block x = 3 after executing inner block
 

Explanation:

None

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.