ProgrammingHard
int x = 1; { int x = 2; printf("%d", x); } printf("%d", x); What is printed?
- A. 12
- B. 21
- C. 22
- D. 11
Correct answer: B. 21
The inner block declares a new x that hides the outer one, so the first print is 2. After the block, x is 1 again.
More C Programming questions
- printf("%d", (int)'A' + 'x01'); What is printed?
- for (char c = 'z'; c > 'w'; c--) putchar(c); What is printed?
- printf("%d", sizeof(void ) == sizeof(int )); What is printed?
- int a[3]; int p = a; printf("%d", p + 3 > a); What is printed?
- struct { int x; int y; } p = {.y = 2, .x = 1}; printf("%d", p.x + p.y); What is printed?
- long long x = 1LL << 40 >> 39; printf("%lld", x); What is printed?