Lesson 3
Keywords in C++
A focused lesson on C++ reserved words and how they work.
Lesson content
Keywords in C++
Keywords are the reserved words in C++ that have a predefined meaning. They form an important part of C++ syntax and cannot be used as names for variables, classes, or functions.
What makes a keyword special
- Keywords are predefined and reserved by the language.
- Each keyword has a special meaning in C++.
- Keywords are always written in lowercase.
- Keywords cannot be used as identifiers.
Examples of C++ keywords
- class
- while
- for
- template
- virtual
- public
- private
- return
Rules for identifiers
Identifiers are the names you assign to variables, constants, functions, classes, and other entities. They must follow C++ naming rules and must not match reserved keywords.
- The first character must be a letter or underscore.
- Identifiers cannot start with digits, but they may contain digits later.
- Whitespace cannot be included.
- Identifiers are case sensitive.
- Avoid starting with double underscores or underscore followed by uppercase (reserved for compiler/library).
Valid and invalid examples
- Valid: myVariable, MAX_SIZE, _count, calculateSum
- Invalid: 123variable, my-variable, my variable