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:
%dint,%ldlong,%lldlong long,%fdouble,%cchar,%sstring,%zusize_t,%ppointer. int / intis whole-number division; make one sidedoublefor a fraction.- A local variable without a value holds garbage — always initialise it.
boolneeds<stdbool.h>; it prints as0or1.