Month End Sale: Get Extra 10% OFF on Job-oriented Training! Offer Ending in
D
H
M
S
Get Now
Identifiers in C++: Differences between keywords and identifiers

Identifiers in C++: Differences between keywords and identifiers

21 May 2024
Beginner
6.05K Views
4 min read
Learn via Video Course & by Doing Hands-on Labs

Free C++ Course Online with Certificate [Full Course]

Identifiers in C++: Overview

Understanding how to use identifiers in C++ can be a daunting task for any beginner. If you're a beginner in programming struggling to understand identifiers in C++, enroll in our C++ beginner course and get the guidance you need. Identifiers are essential concepts in C++. In this C++ tutorial, we'll look at understanding the common identifiers used in the C++ language, including their characteristics, examples, as well as important conventions.

What are Identifiers in C++?

Identifiers are names used to identify memory locations, functions in C++, and variables in C++. These names serve as labels to identify and access these elements within your C++ program.
  • It’s a collection of alphanumeric characters that begins with an alphabetical character or an underscore.
  • As they must be unique, they are case-sensitive.
  • There is a total of 63 alphanumerical characters that represent the identifiers.

Identifier Naming Rules in C++

  • It can only consist of letters (both uppercase and lowercase), digits, and underscores.
  • It must begin with a letter or an underscore. It cannot be a digit.
  • They are case-sensitive, which means uppercase and lowercase letters are considered different characters. E.g., "myVar" and "myvar" are two different identifiers.
  • They cannot be the same as any reserved words in the C++ language. Examples of reserved words in C++ include "if", "while", and "for".
  • Identifiers cannot contain any spaces or special characters such as @, #, $, %, ^, &, *, etc.

Examples of Valid Identifiers

total, sum, average, _m _, sum_1

Example of Invalid Identifiers

2sum (starts with a numerical digit) 
int (reserved word) 
char (reserved word) 
m+n (special character, i.e., '+')

Read More - Advanced C++ Interview Interview Questions and Answers

Types of Identifiers in C++

Types of Identifiers in C++

There are two types of identifiers in the C++ language

  1. Internal Identifiers

  • They aren’t used in external linkage. Ex. local variables
  • They are often used to assign significant meaning to portions of code that are shared between different functions in C++ language, classes, etc.
  • They make it easier to maintain, extend, and debug code in C++.
  • They discourage repetitive copy and paste of code between various program parts.
  • Internal identifiers for variable & function names improve the efficiency and structure of C++ development, resulting in clear, succinct, and error-free code.

  1. External Identifiers

  • Variables, constants, and functions that can be accessed outside of their scope in C++ are given distinctive names known as external identifiers.
  • These identifiers are essential for larger programs with several files and libraries since they ensure organization and proper reference of items outside of their original scope.
  • They are often written in lowercase and start with an underscore (_).

Differences between keywords and identifiers in C++

IdentifiersKeywords
Identifiers are mainly a particular kind of name that identifies elements of that program by the programmers.Keywords are mainly a particular type of word whose meaning is stored by compilers.
It contains digits, letters, and underscore.It contains letters only.
The name of the variable can be identified by identifiersThe types of entities in the program are specified by Keywords
The initial letter of the identifiers can be uppercase, lowercase, or underscore The initial letter of the keyword is started in lowercase
The only special character is used in identifiers are underscoreIn keywords, there are no special characters
There are two types of identifiers, those are internal and external identifiersThere are no classifications in keywords
Examples of identifiers are, results, sum, test, power, and many moreExamples of keywords are, if, for, break, else, and many more
Summary
Having reviewed the components of C++ programming, it is clear that identifiers are key elements to be familiar with when learning how to code in this language. These tools may appear daunting at first, however, over time they can become second nature. For hands-on and practical understanding, consider our C++ Certification Course.

Share Article

Live Classes Schedule

Our learn-by-building-project method enables you to build practical/coding experience that sticks. 95% of our learners say they have confidence and remember more when they learn by building real world projects.
Software Architecture and Design Training Jul 28 SAT, SUN
Filling Fast
05:30PM to 07:30PM (IST)
Get Details
.NET Solution Architect Certification Training Jul 28 SAT, SUN
Filling Fast
05:30PM to 07:30PM (IST)
Get Details
Azure Developer Certification Training Jul 28 SAT, SUN
Filling Fast
10:00AM to 12:00PM (IST)
Get Details
Advanced Full-Stack .NET Developer Certification Training Jul 28 SAT, SUN
Filling Fast
07:00AM to 09:00AM (IST)
Get Details
ASP.NET Core Certification Training Jul 28 SAT, SUN
Filling Fast
07:00AM to 09:00AM (IST)
Get Details
Data Structures and Algorithms Training with C# Jul 28 SAT, SUN
Filling Fast
08:30PM to 10:30PM (IST)
Get Details
Microsoft Azure Cloud Architect Aug 11 SAT, SUN
Filling Fast
03:00PM to 05:00PM (IST)
Get Details
Angular Certification Course Aug 11 SAT, SUN
Filling Fast
09:30AM to 11:30AM (IST)
Get Details
ASP.NET Core Project Aug 24 SAT, SUN
Filling Fast
07:00AM to 09:00AM (IST)
Get Details

Can't find convenient schedule? Let us know

About Author
Shailendra Chauhan (Microsoft MVP, Founder & CEO at Scholarhat by DotNetTricks)

Shailendra Chauhan is the Founder and CEO at ScholarHat by DotNetTricks which is a brand when it comes to e-Learning. He provides training and consultation over an array of technologies like Cloud, .NET, Angular, React, Node, Microservices, Containers and Mobile Apps development. He has been awarded Microsoft MVP 8th time in a row (2016-2023). He has changed many lives with his writings and unique training programs. He has a number of most sought-after books to his name which has helped job aspirants in cracking tough interviews with ease.
Self-paced Membership
  • 22+ Video Courses
  • 800+ Hands-On Labs
  • 400+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Accept cookies & close this