ProgrammingHardTCS NQT · Product company OA
What is printed?
What is printed?
int x = 9, y = 0;
if (x = y == 0) printf("A%d", x);
else printf("B%d", x);- A. B0
- B. A9
- C. A1
- D. A0
Correct answer: C. A1
== binds tighter than =, so this is x = (y == 0). y == 0 is 1, so x becomes 1 and the condition is true: A1. Writing (x = y) == 0 would give A0.
More C Programming questions
- What is printed? c int f(int a, int b) { return a 10 + b; } int main(void) { printf("%d", f((1, 2), 3)); }
- What is printed? c int x = 0; if (x == 1); x += 5; printf("%d", x);
- What is printed? c int inc(int x) { return x + 1; } int dec(int x) { return x - 1; } int (pick(int c))(int) { return c ? inc : dec; } int…
- What is printed? c #include <limits.h> printf("%u %d", UINTMAX + 1u, UINTMAX == -1);
- What is printed? c int ways(int a, int n, int t) { if (t == 0) return 1; if (n == 0 || t < 0) return 0; return ways(a + 1, n - 1, t…
- What value does this call to printf return? c printf("%5.1f|%-5d|", 3.14159, 42);