ProgrammingHardTCS NQT · Infosys
uint8_t a = 200, b = 250; uint8_t avg = (a + b) / 2; What is avg?
- A. 193
- B. 97
- C. 0
- D. 225
Correct answer: D. 225
a + b is computed in int as 450, so the division gives 225, which fits in uint8_t. Wrapping the sum to 8 bits first would wrongly give 97.
More C Programming questions
- What is the value of 1 + 2 3 << 1 in C?
- How many positive divisors does 40 have?
- int next(void) { static int c = 0; return ++c; } Each of three calls returns its value, and the three returns are added together. What is…
- char s[] = "a0b"; What is strlen(s)?
- uint32t v = 0; for each digit d of the decimal string "4294967296", v = v 10 + d; What is v at the end?
- Using fib-like recursion where a stair can be climbed by 1 or 2 steps, the number of ways for 10 stairs is the recursion W(n) = W(n-1) +…