Implicit Conversions
Automatic promotions.
What Is a Conversion
When C combines values of different types, it automatically converts one to the other. This is an implicit conversion.
#include <stdio.h>
int main(void) {
int i = 5;
double d = i;
printf("d = %.1f\n", d);
return 0;
}Integer Promotion
Small integer types like char and short are promoted to int before arithmetic.
#include <stdio.h>
int main(void) {
char a = 10, b = 20;
int sum = a + b;
printf("sum = %d\n", sum);
return 0;
}All lessons in this course
- Implicit Conversions
- Explicit Casts
- Integer and Float Conversions
- Conversion Pitfalls