#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<int> v = {1, 2, 3, 4, 5, 6, 7};
int i = -4;
cout << i << endl;
cout << v.size() << endl;
cout << i % v.size() << endl;
cout << -4 % 7 << endl;
}
Run Code Online (Sandbox Code Playgroud)
The above code prints:
-4
7
5
-4
Run Code Online (Sandbox Code Playgroud)
Can someone please explain why i % v.size() prints 5 instead of -4? I'm guessing it has something to do …