ProgrammingHardTCS NQT · Infosys
uint32_t x = 0x7FFFFFFFu; x = x * 2u + 1u; What is x?
- A. 4294967295
- B. 0
- C. 4294967294
- D. 2147483647
Correct answer: A. 4294967295
x * 2u wraps to 0xFFFFFFFE, and adding 1u gives 0xFFFFFFFF, which is 4294967295. The value never leaves the unsigned range, so the result is defined.
More C Programming questions
- For an unsigned integer x, which expression clears the lowest set bit of x?
- uint8t a = 0xF0, b = 0x3C; uint8t c = a & ~b; What is c?
- uint16t a = 3, b = 5; printf("%d", (a - b) > 0); prints what?
- uint32t p = 65536u 65536u; What is p?
- uint64t f = 1; for (uint64t i = 1; i <= 21; i++) f = i; What is f after the loop?
- How many subsets of {1, 2, 3, 4, 5} have a bitwise XOR of their elements equal to 0? Count the empty set.