ProgrammingHardTCS NQT · Infosys
int a = -7, b = 2; What is a / b * b + a % b?
- A. 0
- B. -6
- C. 5
- D. -7
Correct answer: D. -7
C division truncates toward zero, so a / b is -3 and a % b is -1. The identity (a / b) * b + a % b = a holds, so the result is -7.
More C Programming questions
- int m[2][2] = {{1, 2}, {3, 4}}; int (r)[2] = m; What is r[1][0] + (r[0] + 1)?
- uint32t n = 100000u; uint32t t = n (n + 1) / 2; What is t?
- int x = 0; for (int i = 0; i < 5; i++) x = x ^ i << 1; What is x at the end?
- uint16t a = 300, b = 300; uint16t p = a b; What is p?
- What does printf("%d", strcmp("apple", "Apple") > 0) print?
- A stair can be climbed by 1, 2 or 3 steps. How many ways are there to climb 4 stairs?