Home / Programs / Write a program that illustrates the scope rules in blocks.
Programming Example

Write a program that illustrates the scope rules in blocks.

👁 953 Views
💻 Practical Program
📘 Step by Step Learning
Write a program that illustrates the scope rules in blocks.

Program Code

#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

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.