C Programming Tutorial 0/65 lessons ~6 min read Lesson 10

    Data Types

    Types tell the compiler how to interpret bits — integers, characters, and floating-point forms each have rules for size, range, and printf/scanf specifiers.

    Course progress0%
    Focus
    10 guided sections
    Practice signal
    Examples included
    Career prep
    Foundation builder

    Introduction

    Types tell the compiler how to interpret bits — integers, characters, and floating-point forms each have rules for size, range, and printf/scanf specifiers.

    Understanding the topic

    Integer types char, short, int, long — signed or unsigned.

    Floating point float (single), double (double precision).

    Format specifiers %d int, %c char, %f float, %lf double, %s string.

    • Integer types — char, short, int, long — signed or unsigned.
    • Floating point — float (single), double (double precision).
    • Format specifiers — %d int, %c char, %f float, %lf double, %s string.

    Step-by-step explanation

    1. Integer types — char, short, int, long — signed or unsigned.
    2. Floating point — float (single), double (double precision).
    3. Format specifiers — %d int, %c char, %f float, %lf double, %s string.

    Syntax reference

    Syntax reference:

    c
    int | char | float | double | short | long

    Informative example

    Example program:

    c
    #include <stdio.h>
    int main(void) {
    int i = 42;
    char c = 'X';
    float f = 3.14f;
    double d = 3.1415926535;
    printf("int:%d char:%c float:%f double:%lf\n", i, c, f, d);
    return 0;
    }

    Output

    int:42 char:X float:3.140000 double:3.141593

    Execution workflow

    1Data Types — step by step
    1 / 3

    Integer types

    char, short, int, long — signed or unsigned.

    Best practices

    • Enable warnings: gcc -Wall -Wextra -std=c11 source.c -o app
    • Give every variable a defined value before it is read.
    • Stay inside array bounds — C will not stop you from over-running a buffer.

    Common mistakes

    • Reading uninitialized storage — behavior is undefined.
    • Dismissing compiler warnings instead of fixing root causes.
    • Ignoring NULL returns from malloc, fopen, and similar APIs.

    Hands-on exercise

    Practice problems:

    • Print sizeof each type
    • Use correct specifier for each variable

    Summary

    Data Types in C — Integer, character, and floating forms plus printf format codes.

    Ready to mark this lesson complete?Track your journey across the entire course.