ProgrammingVery hardGATE CS · Campus placements
unsigned int u = 5u; int s = -5; printf("%s", (u + s == 0) ? "yes" : "no"); What is printed?
- A. yes
- B. no
- C. compile error
- D. undefined
Correct answer: A. yes
s is converted to unsigned, giving 2^32 - 5, and 5 + (2^32 - 5) wraps to 0. The comparison is therefore true.
More C Programming questions
- uint32t mask = 0; for (int i = 0; i <= 30; i += 3) mask |= 1u << i; How many set bits does mask have?
- unsigned int v = (unsigned int)(-2); printf("%X", v); What is printed?
- int a[3] = {1, 2, 3}; int p = a; int (q)[3] = &a; printf("%d", (q + 2) + (p + 1)); What is printed?
- unsigned char x = 0; x--; What is x?
- Which statement about the return value of strcmp is true?
- For 4-bit masks (bits 0 to 3), how many masks have both bit 0 and bit 2 set?