This code snippet:
#include <iostream>
#include <cstddef>
int main()
{
int a{-4};
std::size_t b{3};
std::cout << a % b;
return 0;
}
prints
0
while this code snippet:
#include <iostream>
int main()
{
int a{-4};
int b{3};
std::cout << a % b;
return 0;
}
prints
-1
So, why does the first code snippet returns 0
? Why does changing b
from std::size_t
to int
print the right result?