Given this Example:
std::vector<int> numbers = {5,6,7}; //size is 3
int i = -1;
std::cout << i % 3 <<"\n"; // output: -1
std::cout << i % numbers.size() << "\n"; // output: 0
basically in both statements im processing -1 % 3 but the compiler outputs different numbers. I don't understand this outcome, maybe someone can explain it to me.
edit: as @Chris,@Keith Thompson @AnT suggested the snippet
std::cout << std::numeric_limits<std::size_t>::max() % 3 <<"\n"; //output: 0
std::cout << i % numbers.size() << "\n"; // output: 0
prints the expected output. Thanks for the helpful advice to everyone!