Originally Posted by
GokhanK
Type promotion rules says: If one of them is long and the other one is unsigned long, the long one will be converted to unsigned. However it is not certain in the text I have read in an older post what will the type of the final result. But I think it will be unsigned long too.
Nope! it depends entirely on how the result is stored / displayed.
Run the below snippet of code and notice the difference in outputs.
Code:
printf("%ld\n", -2L * 2UL); /* the result here displayed as signed long */
printf("%lu\n", -2L * 2UL); /* the result here displayed as unsigned long */
What you're talking about comes in play only when doing a comparison, as in
Code:
if (-2L * 2UL < 0)
printf("result is signed\n");
else
printf("result is unsigned\n");