简体   繁体   中英

What is the result type of operation between integer literals?

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM