Search

C++ Identifiers

C++ identifiers in a program are used to refer to the name of the variables, functions, arrays, or other user-defined data types created by the programmer. They are the basic requirement of any language. Every language has its own rules for naming the identifiers.

In short, Type of Identifiers are



  • Constants

  • Variables

  • Functions

  • Labels

  • Defined data types


Constant – In Cpp, constant is what ?

Which is Constant ?

Who remains constant throughout the program

Example- Suppose int a=5;

Let’s see a simple program to implement the constant


  • #include<iostream>

  • using namespace std;

  • int main()

  • {

  • int a=5;

  • cout<<a;

  • }


Output –


5



So, the value of “a” is going to remain same throughout the program


Variable – What is a variable ?

Whose value vary throughout the program

Example – for(int i=0; i<5; i++)

Here i is incrementing so it is a variable.


Let’s see a simple program to implement variable

  • #include<iostream>

  • using namespace std;

  • int main()

  • {

  • for(int a=0; a<5; a++)

  • {

  • cout<<a<<endl;

  • }

  • }



Output –


0

1

2

3

4


There are some rules in C++ language to define an identifier


· Only alphabets, characters, digits & underscores are allowed.

· The identifier name must not start with a digit ex 0 to 9. First letter must be alphabetical

· Uppercase & Lowercase letters are different in C++ language

· A keyword can’t be used as variable name


Example of Valid Identifiers

Result

test

test1

Result1

Example of Invalid Identifiers

test-1 //contains special char – Not Allowed

2test //first letter is a digit – Not Allowed

while //Keyword in C++ - Not Allowed




To Avoid confusion between identifiers & keywords let’s see quick differences between them


Keywords are the reserved words predefined in the language but Identifiers are words we used to define a constant or variable.


S. No.

Identifiers

Keywords

0

Identifiers are the names defined by programmers/coders/developers to declare a variable during programming/coding.

Keywords are the reserved words made by compiler developer or we can say they are pre-defined in a language.

1

Contains letters, numbers, underscore

Contain only letters

2

Both lowercase & uppercase letters are allowed

Only lowercase tutorials are allowed

3

Used to identify the name of variable

Used to specify the type of entity.

4

Use of underscore is allowed

Use of Underscore is not allowed

5

The starting letter of underscore is small alphabet, large alphabet or underscore.

Only Lowercase letter is allowed.

6

Further classification of two types – internal & external

No further classification

7.

Examples – test, result, sum, a..

Examples – if, else, while, for, break…



Move to Next Page

---------------------------------------------------------------------------------------------------------------------------

Previous Page Next Page


Any Doubt ? Feel free to write a comment

Download C++ Projects

Join us on LinkedIn – Great Place of Networking

Follow us on More Together – Facebook for regular updates

Mandatory to join Telegram group for regular job updates

Mandatory to join whatsapp group for regular job updates


Other C++ Topics



For Other Tutorials – Click Here


5 views0 comments

Related Posts

See All

Number to Character Conversion in C++

Program to implement Number to Character Conversion in C++ Firstly see what we are going to do ? Like this 0 - zero 1 – one 2 – two 3 – three 4 – four 5 – five 6 – six 7 – seven 8 – eight 9 – nine How

Factorial of a number in C++

In this tutorial we are going to see how to find a factorial of number using C++ program Firstly let’s see a example to understand it better n! = n + (n-1) + (n-2) ! n>=1 3! = 3 *2*1 = 6 Program to fi

Fibonacci Triangle in C++

Program to implement Fibonacci Triangle in C++ #include <iostream> using namespace std; int main() { int a=0,b=1,i,c,n,j; cout<<"Enter the limit: "; cin>>n; for(i=1; i<=n; i++) { a=0; b=1; cout<<b<<"\

Info © Copyright 2020-21 Fresher Side. All rights reserved. Contact us