C | Variable Declaration and Scope | Question 5
Output?
int main() { { int var = 10; } { printf("%d", var); } return 0; } |
chevron_right
filter_none
(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
Recommended Posts:
- C | Variable Declaration and Scope | Question 3
- C | Variable Declaration and Scope | Question 8
- C | Variable Declaration and Scope | Question 7
- C | Variable Declaration and Scope | Question 6
- C | Variable Declaration and Scope | Question 4
- C | Variable Declaration and Scope | Question 2
- C | Variable Declaration and Scope | Question 1
- Scope rules in C
- Redeclaration of global variable in C
- C | Operators | Question 21
- C | Operators | Question 24
- C | Operators | Question 26
- C | Operators | Question 27
- C | Misc | Question 6
- C | String | Question 16
Improved By : mayank5326



