ProgrammingVery hardTCS NQT · Infosys
uint16_t v = 0xFFFFu; v = v << 4; What is v afterwards?
- A. 0xFFFF0
- B. 0xF000
- C. 0xFFF0
- D. 0x0FFF
Correct answer: C. 0xFFF0
v is promoted to int, so v << 4 is 0xFFFF0. Storing that in a 16-bit unsigned type keeps only the low 16 bits, giving 0xFFF0. Bits shifted out of an unsigned value are discarded, not trapped.
More C Programming questions
- For unsigned int n = 13, what is n ^ (n >> 1)? This is the binary-reflected Gray code of 13.
- What is the bitwise XOR of all integers from 1 to 10, that is 1 ^ 2 ^ 3 ^ ... ^ 10?
- What is the sum of popcount(i) for i = 1 to 8, where popcount counts the set bits?
- uint8t a = 0x3C, b = 0xA5; the statements a ^= b; b ^= a; a ^= b; run in that order. What are a and b afterwards?
- uint8t m = 0x0F; uint8t r = ~m; What is r?
- int a = -1; unsigned int b = 1u; What does if (a < b) evaluate to?