Literals in C
A literal is a value written directly in source: 42, 3.14, 'A', "hello", and (since C23 / stdbool.h) true/false. Integers default to int with U/L/LL suffixes for unsigned/long/long-long; decimals default to double with f/F for float and l/L for long double; 0x marks hex, 0b (C23, or GNU extension) binary, leading 0 octal.
Character literals are ints in C (unlike C++ where 'A' is char!) — sizeof('A') == sizeof(int). String literals are read-only char arrays with an implicit null terminator, and adjacent literals concatenate ("foo" "bar" becomes "foobar"), handy for splitting long strings across lines.
Integer suffixes and bases
42U unsigned, 42L long, 42LL long long; 0xFF hex, 017 octal, 0b1010 binary (C23/GNU) — same values, convenient spellings.
Floating defaults to double
3.14 is double; 3.14f is float. Assigning bare decimals to float narrows and may warn.
Char literals are ints
In C, 'A' has type int (value 65) — a classic interview trap distinguishing C from C++.
Strings concatenate and terminate
"foo" "bar" pastes into "foobar" at compile time; every literal carries a hidden trailing '\0'.
#include <stdio.h> int main(void) { int hex = 0x2A; long long big = 3000000000LL; float f = 2.5f; printf("%d, %lld, %.1f\n", hex, big, f); return 0;}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in C yourself — building beats watching.