C Academy · Lesson

Implicit Conversions

Automatic promotions.

Lesson 1 of 413 steps

Implicit Conversions is a free C Academy lesson on CoddyKit. This is lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C Academy learning path, and your progress syncs across the web and the CoddyKit app. The C Academy course includes 4 lessons in total.

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;
}

Usual Arithmetic Conversions

In a mixed expression, the narrower operand is converted to the wider type so both match before the operation.

#include <stdio.h>
int main(void) {
    int i = 3;
    double d = 2.0;
    printf("%.1f\n", i + d);
    return 0;
}

int to double

An int assigned to a double is widened safely, keeping its exact value.

#include <stdio.h>
int main(void) {
    int count = 7;
    double avg = count;
    printf("avg = %.1f\n", avg);
    return 0;
}

double to int Truncates

Assigning a double to an int drops the fractional part. There is no rounding.

#include <stdio.h>
int main(void) {
    double d = 9.99;
    int n = d;
    printf("n = %d\n", n);
    return 0;
}

char and int

A char holds a small integer (its character code). It converts to int naturally.

#include <stdio.h>
int main(void) {
    char c = 'A';
    int code = c;
    printf("code = %d\n", code);
    return 0;
}

Conversions in Assignment

The right side is converted to the type of the left side during assignment.

#include <stdio.h>
int main(void) {
    double pi = 3;
    printf("pi = %.1f\n", pi);
    return 0;
}

Mixed Division Surprise

5 / 2 is integer division (2). Make one operand a double to get real division.

#include <stdio.h>
int main(void) {
    printf("%.1f\n", 5 / 2.0);
    return 0;
}

Bool-Like Conversions

In conditions, any nonzero value converts to true and zero to false.

#include <stdio.h>
int main(void) {
    int x = 3;
    if (x)
        printf("nonzero is true\n");
    return 0;
}

Return Value Conversion

A returned value is converted to the function return type. Returning a double from an int function truncates it.

#include <stdio.h>
int half(int n) {
    return n / 2;
}
int main(void) {
    printf("%d\n", half(7));
    return 0;
}

Passing Arguments

Arguments are converted to the parameter type when a prototype is in scope.

#include <stdio.h>
void show(double d) {
    printf("%.1f\n", d);
}
int main(void) {
    show(5);
    return 0;
}

Quick Check

Test your understanding of implicit conversions.

Recap: Implicit Conversions

You learned automatic type conversions.

  • C converts operands to a common type
  • Small ints promote to int
  • int to double widens safely
  • double to int truncates
  • Integer division surprises unless an operand is a double
Free to start

Learn C with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
39
Lessons
144

Frequently Asked Questions

Is the “Implicit Conversions” lesson free?

Yes — the full text of “Implicit Conversions” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C Academy course, upgrade to CoddyKit PRO. The C Academy course includes 4 lessons in total.

What will I learn in “Implicit Conversions”?

Automatic promotions. You practise C Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start C Academy?

No prior experience is required. C Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.

How long does the “Implicit Conversions” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this C Academy lesson?

Yes. Every C Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

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