ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
unsigned int u = -16; /* 32-bit unsigned int */
printf("%d %u %d", 1 << 4, u >> 28, -16 / 4);- A. 16 -1 -4
- B. 16 15 -4
- C. 16 15 -5
- D. 4 15 -4
Correct answer: B. 16 15 -4
1 << 4 = 16. −16 stored in an unsigned int is 0xFFFFFFF0; shifting right by 28 leaves the top four bits, 0xF = 15 (logical shift for unsigned). −16 / 4 is exactly −4. Right-shifting a negative signed value would be implementation-defined, which is why u is unsigned.
More C Programming questions
- What is printed? c int a = 5, b, c; b = a > 3 ? 10 : 20; c = (b == 10) ? a + b : 0; printf("%d %d %d", a, b, c);
- What is printed? c struct A { char c; int i; char d; }; struct B { int i; double d; }; struct C { char c; double d; char e; }; printf("%zu…
- What is printed? c char s = "hello"; printf("%c %c %c", s[1], 4[s], ("abc" + 2));
- What is printed? c int x = 10; int p = &x; int q = &p; q = 20; p += 5; printf("%d", x);
- What is printed? c #define MAX(a, b) ((a) > (b) ? (a) : (b)) int i = 3; int r = MAX(i++, 2); printf("%d %d", r, i);
- What is printed? c unsigned int i; int count = 0; for (i = 3; i >= 0; i--) { if (++count == 5) break; } printf("%d %u", count, i); /…