C Programming • C17 baseline, standards-specific features labeled
Operators, Expressions, and Conversions
Avoid surprises from integer division, precedence, and implicit type conversions.
An expression has both a value and a type. When both operands of division are integers, the fractional part is discarded. Convert an operand to floating point when fractional results are required, and use parentheses to make complex expressions clear.
Example
#include <stdio.h>
int main(void) {
int whole = 17 / 5;
double fractional = 17.0 / 5.0;
printf("%d %.2f\n", whole, fractional);
return 0;
}
What to expect
3 3.40
Key idea: Check the types of operands before choosing an operator; conversions can change the result.