ProgrammingModerateTCS NQT · Wipro
What is printed?
What is printed?
int x = 5;
x = x << 2 >> 1;
printf("%d", x);- A. 10
- B. 40
- C. 20
- D. 2
Correct answer: A. 10
Shift operators group left to right: (5 << 2) >> 1 = 20 >> 1 = 10. Reading it as 5 << (2 >> 1) gives 10 too by coincidence, but '20' forgets the right shift and '2' shifts in the wrong order.
More C Programming questions
- What is printed? c int x = 9, y = 0; if (x = y == 0) printf("A%d", x); else printf("B%d", x);
- 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…