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

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

  •  31-10-2019
  •  | 
  •  

Pregunta

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 ?

No hay solución correcta

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top