ProgrammingModerateTCS NQT · Infosys
unsigned char c = 200; int r = (c * c) >> 8; What is r?
- A. 40000
- B. 156
- C. 0
- D. 157
Correct answer: B. 156
c promotes to int, so c * c is 40000 with no wraparound. Shifting right by 8 divides by 256 and gives 156. A result of 0 would come from wrongly assuming the product wraps in unsigned char.
More C Programming questions
- unsigned char c = 0xF0; printf("%d", ~c); prints what?
- 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?