ProgrammingModerateWipro · Capgemini pattern
What is printed?
What is printed?
int a = -1, b = 1;
if (a > 0)
if (b > 0) printf("X");
else printf("Y");
printf("Z");- A. YZ
- B. Y
- C. Z
- D. XZ
Correct answer: C. Z
An else pairs with the nearest unmatched if, whatever the indentation suggests, so else belongs to if (b > 0). Since a > 0 is false, that whole inner if-else is skipped and only Z prints.
More C Programming questions
- What is printed? c int x = 4; if (x & 1 == 0) printf("even"); else printf("odd");
- What is printed? c int f(int n) { static int s = 0; s += n; if (n > 0) f(n - 1); return s; } ... printf("%d ", f(3)); printf("%d", f(3));
- What is printed? c printf("%d", 2 + 3 << 1 & 7);
- How many of these are correct in C? (i) A global variable without an initialiser starts as 0. (ii) A static local variable is initialised…
- What is f in the declaration int (f)(int); ?
- What is printed? c int a[] = {5, 10, 15}; int p = a; int x = p++; int y = (p)++; int z = ++p; printf("%d %d %d %d", x, y, z, a[1]);