4 Data Types

A data type tells C what you can store. char holds one character; int holds whole numbers. float and double hold decimal values; double usually keeps more significant digits. bool holds true or false; void means no value. short, long and long long give integer types with different ranges. signed allows negatives; unsigned allows only zero and positive values. Ranges depend on your system. long double keeps at least as many significant digits as double. Arrays hold several values; pointers hold addresses. struct groups values, union shares storage between alternatives, and enum names whole-number values. Function types describe inputs and results. Specialist types cover complex numbers and integers with a chosen number of bits.

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

int main(void) {

    char characterVariable = 'a';
    short shortVariable = 10;
    int numberVariable = 205;
    unsigned int unsignedVariable = 300;
    long longVariable = 100000L;
    long long largeVariable = 10000000000LL;
    float floatVariable = 101.86f;
    double doubleVariable = 123.45;
    long double preciseVariable = 123.45L;
    bool booleanVariable = true;

    printf("%c\n", characterVariable);
    printf("%hd %d %u\n", shortVariable, numberVariable, unsignedVariable);
    printf("%ld %lld\n", longVariable, largeVariable);
    printf("%.2f %.2f\n", floatVariable, doubleVariable);
    printf("%.2Lf\n", preciseVariable);
    printf("%d\n", booleanVariable);
    return 0;
}