#include <stdio.h>
main() {
unsigned a = -20;
unsigned b = 10;
printf("%d\n", (a % b));
printf("%d\n", (-20 % 10));
}
Output:
6
0
The second printf prints the expected value of 0 while the first printf prints 6. Why this unexpected output with unsigned ints?