ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
int i = 0, j = 1, k;
k = i++ && j++ || ++j;
printf("%d %d %d", i, j, k);- A. 1 2 1
- B. 0 1 0
- C. 1 2 0
- D. 1 3 1
Correct answer: A. 1 2 1
&& binds tighter than ||: (i++ && j++) || ++j. i++ yields 0, so && short-circuits and j++ never runs (i becomes 1). The left side is false, so ++j runs: j = 2, true, k = 1.
More C Programming questions
- 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");
- What is printed? c float f = 0.1f, g = 0.5f; printf("%s ", f == 0.1 ? "eq" : "ne"); printf("%s", g == 0.5 ? "eq" : "ne");
- On a little-endian machine with 4-byte int and ASCII, what is printed? c union { int i; char c; } u; u.i = 0x41424344; printf("%c", u.c);
- What is printed? c void swap(int x, int y) { x ^= y; y ^= x; x ^= y; } ... int a = 7; swap(&a, &a); printf("%d", a);