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); }
- A.
1 −1
- B.
−1 −1
- C.
−1 1
- 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.