For example, the code below
int a = -7777;
int b = 10;
cout<< a % b<<endl;
cout<<(a+b)%b<<endl;
cout<< -7777%10 <<endl;
Results:
-7
-7
-7
but if I changed type b to unsigned int, it has different meanings;
int a = -7777;
unsigned int b = 10;
cout<< a % b<<endl;
cout<<(a+b)%b<<endl;
cout<< -7777%10 <<endl;
Reserves
9
9
-7
Can any body advise how it works here? How do differences arise?
Btw: I use C ++ in the latest version of Xcode.
source
share