CJCoding With Joseph
15free / daySign inCreate account
← Back to Question List
C++ Code Walkthrough #42

Modulo and Division With Negative Numbers

hardOperators

📄 Code

Read carefully — what does this print?
1#include <iostream>
2using namespace std;
3 
4int main() {
5 cout << -7 / 2 << " " << -7 % 2 << endl;
6 cout << 7 / -2 << " " << 7 % -2 << endl;
7 cout << (-7 / 2) * 2 + (-7 % 2) << endl;
8 return 0;
9}

🎯 Your Answer