literals and constants
When you write a number or a piece of text directly in your code, you are writing it out in plain sight — a literal. The 42 in 'int x = 42;', the 3.14 in a calculation, the 'A' for a single character, and the "hello" in quotes are all literals: fixed values spelled directly into the source. A constant is the broader idea of a value that does not change, and C gives several ways to name one.
Literals come in flavours that match the types: integer literals like 42 (and 0x2A in hexadecimal, 052 in octal, with suffixes like U for unsigned and L for long), floating literals like 3.14 or 1.5e-3, a character literal like 'A' (which is actually an int holding that character's code), and a string literal like "hello" (an array of characters ending in a hidden null terminator). To name a constant, you can write a const variable such as 'const int MAX = 100;', or define a set of named integer constants with an enumeration: 'enum Color { RED, GREEN, BLUE };' makes RED equal 0, GREEN equal 1, and BLUE equal 2 automatically. The preprocessor's #define also makes a constant, but that is a text substitution handled before compilation, covered separately.
Why this matters: naming constants instead of scattering bare numbers (so-called magic numbers) makes code readable and changeable in one place. Enumerations are especially valuable for a fixed list of options — days of the week, error codes, states — because the names document intent and the compiler can help. A small caveat: a string literal must be treated as read-only; attempting to modify the characters of a string literal is undefined behavior.
int n = 42; /* integer literal */ double r = 1.5e-3; /* floating literal */ char c = 'A'; /* character literal (an int code) */ const int MAX = 100; /* a named constant */ enum Color { RED, GREEN, BLUE }; /* RED==0, GREEN==1, BLUE==2 */
Each literal carries a type. An enumeration auto-numbers its names from 0, giving readable constants instead of bare numbers.
A string literal lives in read-only memory; writing through it (e.g. modifying a character of "hello") is undefined behavior. A character literal like 'A' has type int in C, not char.