Usual arithmetic conversions in C : Whats the rationale behind this particular rule

StackOverflow https://stackoverflow.com/questions/8937676

  •  31-10-2019
  •  | 
  •  

문제

From k&R C

  • First, if either operand is long double, the other is converted to long double.
  • Otherwise, if either operand is double, the other is converted to double.
  • Otherwise, if either operand is float, the other is converted to float.
  • Otherwise, the integral promotions are performed on both operands; ...

This would mean below expression

char a,b,c;

c=a+b;

is actually caculated as

c = char((int)a+(int)b);

What is the rationale behind this rule?

Do these conversions happen if a, b and c were short ?

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top