ProgrammingVery hard
With int a = -1 and unsigned int b = 0, what does the expression a < b evaluate to?
- A. 0 (false), because a is converted to unsigned and becomes a huge value
- B. 1 (true), because -1 is less than 0
- C. It is undefined behaviour
- D. A compile error in C
Correct answer: A. 0 (false), because a is converted to unsigned and becomes a huge value
The usual arithmetic conversions turn -1 into 4294967295, which is not less than 0. The result is well defined and surprising.
More C Programming questions
- Using the extended Euclidean algorithm, what is the inverse of 10 modulo 17?
- What is the number of 1 bits in 0xF0F0 (a 16-bit value)?
- An 8-bit value 0b10010110 is rotated left by 3 positions within 8 bits. What is the result in decimal?
- unsigned char s = 0; for (int i = 1; i <= 100; i++) s += i; printf("%d", s); What is printed?
- What is (1ULL << 40) % 1000 in C?
- For the signed integer -17, which expression gives the non-negative remainder modulo 5 in C?