int main(){
char a = 5 (16711935 * 1200);
return 0;
}
Based on the type of integer literals and conversion rules in C, 16711935
is of type int and 1200
is promoted to an int. My question is what is the type of the intermediate result of this multiplcation before it gets added to 5 and then converted to a char?
Does the intermediate result also follow the integer literal rules?
Edit: This question is not specific to multiplication, it is just an example.
CodePudding user response:
The conversion rules apply to all operations involving integer types, whether the operands are integer constants or objects of integer type.
In the case of this expression, the integer constants 5
, 16711935
, and 1200
all have type int
(assuming an int
is 32 bits wide), so there is no conversion applied to the operands of the
and =
operators. The resulting expression has type int
and is converted to char
before being assigned to a
.
The types applied to integer constants are specified on this page, which originates from section 6.4.4.1 of the C standard.