Multiple choice

What does printf(“%d, %d ”, 5/3, 5 % 3) print to standard output?

  1. 1.66, 1 (That is, '1.66', a comma, a space, a '1', and a newline character)

  2. 1.6, 2 (That is, '1.6', a comma, a space, a '2', and a newline character)

  3. 1.666, 0 (That is, '1.666', a comma, a space, a '0', and a newline character)

  4. 1, 2 (That is, a '1', a comma, a space, a '2', and a newline character)

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

In C, integer division (5/3) truncates toward zero, yielding 1 (not 1.66 or decimal values). The modulo operator (5 % 3) gives the remainder, which is 2. Therefore printf with '%d, %d' format prints '1, 2'. The fractional answers A, B, C are incorrect because %d expects integers.