CData Types Overview

Data Types Overview

Every variable in C has a data type that determines two things: how much memory it occupies, and how the bits stored in that memory are interpreted. C's type system is deliberately small and close to the hardware, which is part of why the language maps so directly onto how a CPU actually thinks about numbers and memory.

The fundamental types

C provides a handful of basic (scalar) types built directly into the language. Every other type — arrays, pointers, structures, unions — is built up from these fundamentals or from user-defined combinations of them.

Type

Typical use

Example literal

int

Whole numbers

42, -7

float

Single-precision decimal numbers

3.14f

double

Double-precision decimal numbers (default for real numbers)

3.14159

char

A single byte, usually one character

'A'

void

"No type" — used for functions with no return value, or generic pointers

n/a

C
#include <stdio.h>

int main(void) {
    int    age = 30;
    float  gpa = 3.8f;
    double pi  = 3.14159265358979;
    char   grade = 'A';

    printf("age=%d gpa=%.1f pi=%.5f grade=%c\n", age, gpa, pi, grade);
    return 0;
}
age=30 gpa=3.8 pi=3.14159 grade=A
No built-in bool before C99
Booleans are a recent addition
Classic C has no dedicated `bool` type — truth is represented with plain integers, where `0` means false and any nonzero value means true. C99 introduced `_Bool` as a real (if small) integer type, and the `<stdbool.h>` header adds the friendlier `bool`, `true`, and `false` names as macros on top of it. Even in modern C, `bool` is really just an `int`-like type under the hood, unlike C++'s native `bool`.

C
#include <stdbool.h>
#include <stdio.h>

int main(void) {
    bool is_ready = true;
    if (is_ready) {
        printf("Ready!\n");
    }
    return 0;
}
Derived and user-defined types (a preview)

On top of the fundamental types, C lets you build richer types that we will cover in detail in later sections:

  • Arrays — a fixed-size sequence of values of the same type.

  • Pointers — a variable that stores the address of another variable.

  • Structures (struct) — a bundle of related values, possibly of different types, grouped under one name.

  • Unions (union) — like a struct, but all members share the same memory.

  • Enumerations (enum) — a set of named integer constants.

Checking a type's size with sizeof

C does not fix the exact size of most types in bytes — it only guarantees minimums (covered in depth in Integer Types and Type Sizes & limits.h). To find out how large a type actually is on your platform and compiler, use the sizeof operator.

C
#include <stdio.h>

int main(void) {
    printf("sizeof(int)    = %zu bytes\n", sizeof(int));
    printf("sizeof(double) = %zu bytes\n", sizeof(double));
    printf("sizeof(char)   = %zu bytes\n", sizeof(char));
    return 0;
}
sizeof(int)    = 4 bytes
sizeof(double) = 8 bytes
sizeof(char)   = 1 bytes
Where to go next
This page is the map — the following pages zoom into each type family: integer types and their ranges, floating-point precision, the char type's dual identity as a character and a number, and the void type's special roles.