ProgrammingHardTCS NQT · Infosys
What does printf("%d", -5 % 3) print?
- A. -2
- B. 1
- C. 4
- D. 3
Correct answer: A. -2
C division truncates toward zero, so -5 / 3 is -1 and -5 % 3 is -5 - (-1 * 3) = -2. The sign follows the dividend.
More C Programming questions
- double x = 7 / 2 2.0; printf("%g", x); What is printed?
- unsigned char c = 0x0F; printf("%d", (unsigned char)~c); What is printed?
- int i = 0; if (0 && i++) ; if (1 || i++) ; printf("%d", i); What is printed?
- unsigned char a = 255; printf("%d", a == -1); What is printed?
- long long x = 1000000LL 1000000; What is x?
- What does printf("%d", sizeof('a') == sizeof(int)) print?