ProgrammingModerateTCS NQT · Infosys pattern
What is printed?
What is printed?
int x = 3;
if (x = 0) printf("A%d", x);
else printf("B%d", x);- A. A0
- B. B0
- C. A3
- D. B3
Correct answer: B. B0
x = 0 is an assignment, not a comparison: it stores 0 in x and its value, 0, is false. So the else branch runs and prints B with the new x, 0.
More C Programming questions
- What is printed? c int add(int a, int b) { return a + b; } ... int (fp)(int, int) = add; printf("%d", (fp)(2, 3) + fp(4, 5));
- What is printed? c #define MAX(a, b) ((a) > (b) ? (a) : (b)) int x = 3, y = 5; int z = MAX(x++, y++); printf("%d %d %d", x, y, z);
- What is printed? c int i = 0, j = 1, k; k = i++ && j++ || ++j; printf("%d %d %d", i, j, k);
- What is printed (the code compiles)? c int x = (5, 10, 15); int y; y = 5, 10; printf("%d %d", x, y);
- With 4-byte int, what is printed? c int i = 5; sizet s = sizeof(i++); printf("%d %zu", i, s);
- What is printed? c int a = -1; unsigned int b = 1; if (a < b) printf("less"); else printf("not less");