CJCoding With Joseph
15free / daySign inCreate account
Back to Code Walkthrough

Modulo and Division With Negative Numbers

C++ code walkthrough · Question 42
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