C | Variable Declaration and Scope | Question 5

Output?

filter_none

edit
close

play_arrow

link
brightness_4
code

int main()
{
  {
      int var = 10;
  }
  {
      printf("%d", var);  
  }
  return 0;
}

chevron_right


(A) 10
(B) Compiler Error
(C) Garbage Value


Answer: (B)

Explanation: x is not accessible.

The curly brackets define a block of scope. Anything declared between curly brackets goes out of scope after the closing bracket.

Quiz of this Question



My Personal Notes arrow_drop_up

Improved By : mayank5326



Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.