ProgrammingHardTCS NQT · Infosys
With uint32_t x = 5u - 7u; what is the value of x?
- A. -2
- B. 4294967294
- C. 4294967295
- D. 4294967296
Correct answer: B. 4294967294
Unsigned arithmetic wraps modulo 2 to the power 32, so 5 - 7 becomes 2^32 - 2 = 4294967294. An unsigned type never holds a negative value.
More C Programming questions
- uint32t x = 0x00F0A8u; what is x & (0u - x) in hexadecimal?
- uint32t n = 0xB6u; the loop while (n) { n &= n - 1; count++; } runs with count starting at 0. What is count when the loop ends?
- uint16t v = 0xFFFFu; v = v << 4; What is v afterwards?
- 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?