0Pricing
C Academy · Lesson

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

  1. Implicit Conversions
  2. Explicit Casts
  3. Integer and Float Conversions
  4. Conversion Pitfalls
← Back to C Academy