What is the output of the code written in C? void main() { printf("%d", 7 %…

2021

What is the output of the code written in C? void main() { printf("%d", 7 % -3); printf("%d", -7 % 3); }

  1. A.

    1 −1

  2. B.

    −1 −1

  3. C.

    −1 1

  4. D.

    1 1

Attempted by 535 students.

Show answer & explanation

Correct answer: A

In C, the modulo operator % follows truncation towards zero. For 7 % -3, the sign matches the dividend (positive), yielding 1. For -7 % 3, the sign matches the dividend (negative), yielding -1. The program prints these values consecutively without spaces.

Explore the full course: Up Lt Grade Assistant Teacher 2025