VOOZH about

URL: https://www.geeksforgeeks.org/cpp/cpp-identifiers/

⇱ C++ Identifiers - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C++ Identifiers

Last Updated : 13 Jun, 2026

Identifiers in C++ are user-defined names used to represent program elements such as variables, functions, classes, and objects. They provide a way to uniquely refer to different entities within a program.

  • They are used to label and access different components of a C++ program.
  • They must follow certain syntax rules and recommended naming conventions.

Output
90

This program demonstrates the use of different identifiers in C++, including a class (Student), method (show), variable (marks), object (s1), and function (main). When executed, it creates a Student object and displays the value of the marks variable.

👁 a_

Rules for Naming an Identifier

We can use any word as an identifier as long as it follows the following rules:

  • An identifier can consist of letters (A-Z or a-z), digits (0-9), and underscores (_). Special characters and spaces are not allowed.
  • An identifier can only begin with a letter or an underscore only.
  • C++ has reserved keywords that cannot be used as identifiers since they have predefined meanings in the language. For example, int cannot be used as an identifier as it already has some predefined meaning in C++. Attempting to use these as identifiers will result in a compilation error.
  • An identifier must be unique within its scope (or namespace), meaning you cannot have two identifiers with the same name in the same context.

Additionally, C++ is a case-sensitive language so the identifier such as Num and num are treated as different. The images below show some valid and invalid C++ identifiers.

👁 examples of valid and invalid identifiers
Example of Valid/Invalid Identifiers

Example: Valid and Invalid Identifiers in C++


Output
Total: 25

In this example, identifiers are used according to C++ naming rules in variables, class and function.


Output
The sum is: 12

Related Article

Naming Convention in C++

Comment
Article Tags:
Article Tags: