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

Write a program that illustrates the scope rules in blocks.

👁 956 Views
💻 Practical Program
📘 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;
}
 
                        

🖥 Program 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
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.