Variables and types

Integer and floating types, printf format specifiers, sizeof, casts, and integer division.

Runs in Zerethon IDE · C (GCC 14) Official C documentation ↗
main.c
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int count = 3;
    double price = 9.5;
    long long big = 3000000000LL;
    char grade = 'A';
    bool ready = true;
    const int MAX = 10;

    printf("%d %.2f %lld %c %d %d\n", count, price, big, grade, ready, MAX);
    printf("%d %.1f %d %d\n", 7 / 2, 7 / 2.0, 7 % 2, (int) 3.99);
    printf("%zu %zu\n", sizeof(int), sizeof(double));
    printf("%d %.1f\n", atoi("42") + 1, strtod("2.5", NULL) * 2);
    return 0;
}

Output

3 9.50 3000000000 A 1 10
3 3.5 1 3
4 8
43 5.0
  • Match the specifier to the type: %d int, %ld long, %lld long long, %f double, %c char, %s string, %zu size_t, %p pointer.
  • int / int is whole-number division; make one side double for a fraction.
  • A local variable without a value holds garbage — always initialise it.
  • bool needs <stdbool.h>; it prints as 0 or 1.

Related topics

Official references