Integer promotion - what are the steps
This code prints B2 short a=-5; unsigned short b=-5u; if(a==b) printf("A1"); else printf("B2"); I read about integer promotion but it's still unclear to me, how does it work in the example here? Can someone thoroughly post the steps the compiler follows in widening/truncating the values? Let's walk through your code: short a = -5; a = -5, which fits into a short. So far so easy. unsigned short b = -5u; -5u means apply the unary - operator to the constant 5u. 5u is (unsigned int) 5, and the unary - does no promotion, so you end up with 4294967291 which is 2^32-5. (Update: I got this bit wrong