ProgrammingHardGATE CS · Campus placements
unsigned char c = 0xF0; printf("%d", ~c); prints what?
- A. 15
- B. -241
- C. -16
- D. 4294967055
Correct answer: B. -241
c is promoted to int with value 240, and bitwise NOT on that int gives -241 in two's complement. Printing with %u would instead show 4294967055, and the unsigned char itself never holds a negative value.
More C Programming questions
- int x = 7; int a = &x, b = &x; a ^= b; b ^= a; a ^= b; What is x afterwards?
- int a[] = {5, 1, 4}; int p = a; p++ += 10; printf("%d %d", a[0], p); prints what?
- struct P { int id; int score; }; An array must be sorted by score descending, with ties broken by id ascending, using qsort. Which…
- For a = {2, 4, 2, 2, 6, 4}, how many index pairs i < j satisfy a[i] == a[j]?
- uint32t fact(uint32t n) { return n <= 1 ? 1 : n fact(n - 1); } What does fact(13) return?
- uint8t acc = 0; uint8t a[3] = {250, 3, 7}; for each element, acc += a[i]; What is acc after all three additions?