ProgrammingHardTCS NQT · Infosys
What is printed? Assume unsigned int is 32 bits.
What is printed? Assume unsigned int is 32 bits.
#include <stdio.h>
int main(void) {
unsigned x = 12;
printf("%u", (x << 3) + (x << 1));
}- A. 118
- B. 120
- C. 96
- D. 132
Correct answer: B. 120
x << 3 is 8x and x << 1 is 2x, so the sum is 10x = 120 for x = 12. 96 forgets the second term, and 132 uses 11x.
More C Programming questions
- How many adjacent pairs of 1 bits does 27 (binary 11011) have? The program counts the set bits of x & (x >> 1). c #include <stdio.h> int…
- What is printed? c #include <stdio.h> int main(void) { int b[] = {1, 1, 0, 1, 1, 1, 0, 1, 1, 1}, run = 0, best = 0; for (int i = 0; i <…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {1, 2, 3, 4, 5}; for (int i = 0; i + 1 < 5; i += 2) { int t = a[i]; a[i]…
- What is printed? c #include <stdio.h> int f(int n) { return n <= 1 ? 0 : 1 + f(n / 2); } int main(void) { printf("%d", f(10)); }
- What is printed? Assume uint16t is 16 bits. c #include <stdint.h> #include <stdio.h> int main(void) { uint16t a = 0xFFF0, b = 0x20…
- What is printed? c #include <stdio.h> long long f(int n) { return n == 0 ? 1 : 2 f(n - 1) + 1; } int main(void) { printf("%lld", f(10)); }