C++ identifiers are the unique names assigned by the programmer to the variables, constants, functions or classes, etc. For example int age= 27; where “age” is the identifier given by the developer.
To write any identifier you have to follow a set of rules. Let’s take a look at the rules.
- All alphabets, digits, and underscores are used to write it.
- It can only be started with an alphabet or underscore
- It is a case-sensitive means Logic and logic are two different names
- Keywords cannot be used as identifiers.
- Special characters like “!”, “%”, “#”, and white spaces are not used to declare it.
Example: Valid C++ identifiers
Students | Subject2 | User_Name |
logic | Ashwin | _age |
Example: Invalid C++ Identifiers
Student Marks | int | 2num |
!number | Your-name | break |