I am a student, going through the book by Kerningham and Ritchie for C.
A line in the book says that -1l is less than 1u because in that case unsigned int is promoted to signed long. But -1l > 1ul because in this case -1l is promoted to unsigned long.
I can’t really understand the promotion properly. What will be the value of -1l when it is promoted to unsigned long? It’ll be great if anyone can help.
Thanks.
When you’re learning C, if you have a question, just write yourself a simple program:
You’ll see that
-1l > 1uis shown for the output.Because both
sianduihave the same rank (they’re bothints), the rule says that the negative value will be promoted to unsigned at set toUINT_MAXwhich is the largest possible unsigned value.