a) Convert to the larger type. b) In case of equal size prefer unsigned over signed. You can verify this by changing the declaration of int b to int64_t b (i.e long long int type). The output would now say Negative. NOTE: Don't forget to include stdint.h if you use int64_t..:)
The whole expression get typecasted to unsigned after evaluation? Is this the reason?
ReplyDelete@Spectatot
ReplyDeleteActually, the conversion rules are
a) Convert to the larger type.
b) In case of equal size prefer unsigned over signed.
You can verify this by changing the declaration of int b to int64_t b (i.e long long int type). The output would now say Negative.
NOTE: Don't forget to include stdint.h if you use int64_t..:)