Identifiers & Naming Rules
An identifier is the name you give to a variable, function, type, macro, or any other user-defined entity in a C program. C imposes a small, strict set of rules on what characters an identifier may contain, and a much larger, informal set of naming conventions that the C community has settled on over the decades for writing readable code.
Valid characters
Identifiers may contain letters (a-z, A-Z), digits (0-9), and the underscore (_).
An identifier cannot start with a digit —
2fastis invalid, butfast2is fine.No spaces, hyphens, or other punctuation are allowed inside an identifier.
C is case-sensitive, so
total,Total, andTOTALare three completely different identifiers.
int score; /* valid */ int _hidden; /* valid, but reserved-ish, see below */ int player2; /* valid */ int total_count; /* valid */ /* int 2players; */ /* INVALID: starts with a digit */ /* int player-two; */ /* INVALID: hyphen is not allowed */ /* int player two; */ /* INVALID: space is not allowed */
Reserved keywords
C reserves around 32 to 44 keywords (depending on the standard version) for the language itself, such as int, return, for, while, struct, and static. These words have special meaning to the compiler and cannot be used as identifiers for your own variables or functions.
/* int return = 5; */ /* INVALID: 'return' is a reserved keyword */ int result = 5; /* valid alternative */
Naming conventions
The C standard itself has no opinion on style beyond the character rules above, but decades of shared practice have produced strong conventions that most C codebases follow.
Convention | Typical use | Example |
|---|---|---|
snake_case | Variables and function names (dominant in C) |
|
ALL_CAPS | Macro constants defined with |
|
PascalCase | Occasionally for type/struct names in some codebases |
|
Leading underscore | Reserved for the implementation — avoid in your own code |
|
Identifiers starting with underscore are reserved
/* Avoid these in your own code: */ int __count; /* reserved: leading double underscore */ int _Value; /* reserved: underscore + uppercase letter */ /* Prefer plain, descriptive names instead: */ int count; int value;
Identifiers: letters, digits, and underscore only; cannot start with a digit.
C is case-sensitive —
Dataanddataare different names.Reserved keywords (
int,for,return, etc.) cannot be used as identifiers.Follow snake_case for variables/functions and ALL_CAPS for macro constants.
Never start your own identifiers with an underscore — that space belongs to the implementation.