Casting without an explicit cast operator is completely legal in C, but it can have undefined behavior. In your case, int x; is signed, so if you try to store a value in it outside the int range, your program has undefined behavior. On the other hand, if x was declared as unsigned x; , the behavior is correctly defined; casting is carried out by decreasing modulo UINT_MAX+1 .
As for arithmetic, when you do arithmetic between integers of different types, the type of "smaller" advances to the "larger" type before arithmetic. The compiler is free to optimize this ad if it does not affect the results, which leads to idioms such as casting a 32-bit integer to 64 bits before multiplication to get the full 64-bit result. Promotion becomes a bit confusing and can have unexpected results when mixing values under a sign and an unsigned one. You must watch it if you want to know, because it is difficult to explain informally.
source share