For a little bit of code:
printf ("%d",sizeof('A'));
Are you sure he's printing 1?
After running, the result is 4!
C-Type conversions are more common than most people think , and in expressions involving less than int and double, there is a possibility of a type conversion!
According to the promotion rule: it is converted from char to int. This feature is called type Promotion!
Char c1,c2;...........c1=c1+c2;
The following table shows a list of common types of promotion:
char-------------------------> int
Enum (enum)-------------------------> int
unsigned char-------------------------> int
Short-------------------------> int
unsigned short-------------------------> int
Bit segment (bit-filed)-------------------------> int
Float-------------------------> Double
' Integer lift ' requires the abstract machine to promote each variable to an int length, then add two int and then crop the result. If the addition of two char does not result in an overflow exception,
Then the actual execution only needs to produce the result of the char type, you can omit the type promotion!
Similar:
In:
float F1,f2; Double d;f1=f2*d;
If the compiler determines that the result of the operation with float is the same as converting to double, you can also use float for multiplication!
The hermit type conversion is a kind of method in language, which originates from the idea of simplifying the original editor.
C-Language unusual type conversions (type promotion)