Learn C++
#include "gettingstarted/keywords_identifiers.hpp"

Keywords and Identifiers in C++

//concept

Keywords are words the language owns permanently — int, class, if, return, while, and about ninety others — and they can never be reused as names. Identifiers are the names you invent for variables, functions, and classes: they must start with a letter or underscore, followed by letters, digits, or underscores.

C++ is case-sensitive, so score, Score, and SCORE are three different names. Identifiers with a leading underscore followed by a capital letter (like _Foo) are reserved for the implementation — never invent those yourself, or your code can silently collide with compiler internals.

//how it works
1

What counts as a keyword

A fixed reserved word such as int, for, class, or new — always meaningful to the compiler, never usable as a variable or function name.

2

What counts as an identifier

Any name you invent. It must begin with a letter or underscore and contain only letters, digits, and underscores after that.

3

Case sensitivity

count and Count are completely different identifiers — capitalization is never ignored, so pick one style and stay consistent.

4

Reserved patterns to avoid

Leading double underscores (__x) and leading underscore plus capital (_X) belong to the compiler and standard library — treat them as off-limits.

//example
#include <iostream>
 
int main() {
int player_score = 10;
int Player_score = 20;
std::cout << player_score << " vs " << Player_score << std::endl;
return 0;
}
Output
10 vs 20
1int and return are keywords — trying to name a variable int would fail to compile.
2player_score and Player_score differ only in one capital letter, so the compiler treats them as two independent variables.
3The single output line prints both values, proving the two names hold separate data.
//use cases
Understanding an expected identifier before ... error pointing at a keyword misused as a name
Catching a bug where Score and score were meant to be the same variable
Following a codebase's snake_case vs camelCase convention for new names
Avoiding reserved _Capital names in headers that could clash with the standard library

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in C++ yourself — building beats watching.