C++ Identifiers

Identifiers are the basic building blocks of a program. Identifiers are used as a general name given to different parts of the program namely variables, objects, classes, functions, arrays etc. Identifier forming rule of C++ states the following :

An identifier is an arbitrarily long sequence of letters and digits. The first character must be a letter; the underscore ( _ ) counts as a letter. Upper and lower-case letters are different. All characters are significant.

C++ is a case-sensitive language as it treats upper and lower-case characters differently.

Legal Identifiers in C++

Following are some legal Identifiers in C++ :

Myfile   BAL3_23_76   Z23T02A9   MYFILE
_DGE   _HL3_SD   _CHK   FILE23

Some Invalid Identifiers

Following are some invalid Identifiers :

DATA-REC      contains special character - (other than A-Z, a-z, and _)
35CLTU        starting with a digit
continue      reserved keyword
My.file       contains special character

Tip : You may either use underscore in variable names to separate parts of the name, such as last_name, first_name, main_balance, or you may go for "capital style" notation, such as lastName, firstName, mainBalance, i.e., capitalizing first letter of next word.

C++ Identifiers Example

Following C++ program is an example program of C++ Identifiers which gives you some idea about uses of identifiers in C++ programming :

/* C++ Identifiers Example */


void main()

   char ch;        // here ch is an identifier
   char Name[20];  // here Name is an identifier
   int num;        // here num is an identifier

   cout<<"Enter a character : ";
   cout<<"You entered "<<ch;

   cout<<"\nEnter your name : ";
   cout<<"Your name is "<<Name;

   cout<<"\nEnter a number : ";
   cout<<"You entered "<<num;


When the above C++ program is compile and executed, it will produce the following output:

c++ identifiers

More Examples

Here are some more C++ programs listed, that you can go for to see more identifier:

C++ Online Test

« Previous Tutorial Next Tutorial »

Like/Share Us on Facebook 😋