Explanatory Question
What is Blocks and Scope in c ?
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.
C is a block-structured language. Blocks are delimited by { and}. Every block can have its own local variables. Blocks can be defined wherever a C statement could be used. No semi-colon is required after the closing brace of a block.
Code:
#include #define semicolon ; void main() { int a = 5; printf("\n%d", a); { int a = 2; printf("\n%d", a); } }
Output:
5 2Press any key to continue . . .
Reference to a variable will be to the variable of that name in the nearest enclosing block.
First read the answer fully, then try to explain it in your own words. After that, open a few related questions and compare the concepts. This method helps you remember the topic for a longer time and improves exam preparation.