Keywords in C++ | List of all keywords in C++ ( Full Explanation ) (2024)

21 May 2024

Beginner

16.9K Views

9 min read

Keywords in C++ | List of all keywords in C++ ( Full Explanation ) (1)

Learn via Video Course & by Doing Hands-on Labs

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

Free Course Hands-On Labs

Free Course Self Paced Courses Hands-On Labs

Keywords in C++: An Overview

Keywords are reserved terms in the C++ programming language that have preset meanings. These words cannot be used as identifiers (for example, variable names) yet are critical to program structure and functionality. e.g. "int," "if," "while," and "class." They are essential building blocks for writing code, aiding in the definition of data types, control flow, and object-oriented notions. In this C++ tutorial, we will understand what are tokens and keywords.

Tokens in C++

Tokens, the smallest individual unit, comprises a C++ program. Tokens can be keywords, identifiers, constants, operators, or punctuation marks, among other things.

Tokens in C++ are classified into six types:

  • Keywords
  • Identifiers
  • Constants
  • Strings
  • Special symbols
  • Operators

Keywords in C++ | List of all keywords in C++ ( Full Explanation ) (3)

Read More - C++ Interview Interview Questions and Answers

What is a Keyword in C++?

Keywords or reserved words convey a specific meaning to the compiler of C++ programs and it is always written in lower cases. Keywords in C++ language are generally used for serving some special functions such as void, int, publicand many more.

Types of keywords in C++

If the question is how many keywords are in C++ then the answer will be, that C++ language has 32 various types of keywords.

C++ Keywords

asmdoublenewswitch
autoelseoperatortemplate
breakenumprivatethis
caseexternprotectedthrow
catchfloatpublictry
charforregistertypedef
classfriendreturnunion
constgotoshortunsigned
continueifsignedvirtual
defaultinlinesizeofvoid
deleteintstaticvolatile
dolongstructwhile

Explanation of Keywords in C++

  • Asm: It is used to declare a block of code that has to be passed to the assembler.
  • auto: This keyword is a storage class specifier that is used for defining objects in a particular block.
  • break: This statement terminates any switch statement or any loop.
  • case: This keyword is used specifically within a switch statement to specify a match for the expression of the statement.
  • catch: It specifies which actions have to be taken when an exception occurs.
  • char: This is one of the fundamental data types in C++ language that defines character objects.
  • class: It is used to declare a user-defined data type that encapsulates any data members and operations or member functions of a particular class.
  • const: This keyword helps to define objects whose value will not alter throughout the lifetime of execution of that particular program.
  • continue: It transfers control to the starting point of a loop.
  • default: This keyword handles expression values in a switch statement that could not be handled by case.
  • delete: It is a memory deallocation operator.
  • do: indicate the start of a do-while statement in which the sub-statement is executed repeatedly until the value of the expression is logical-false.
  • double: Fundamental data type used to define a floating-point number.
  • else: Used specifically in an if-else statement.
  • enum: To declare a user-defined enumeration data type.
  • extern: An identifier specified as an extern has an external linkage to the block.
  • float: Fundamental data type used to define a floating-point number.
  • for: Indicates the start of a statement to achieve repetitive control.
  • friend: A class or operation whose implementation can access the private data members of a class.
  • long: A data type modifier that defines a 32-bit int or an extended double.
  • new: Memory allocation operator.
  • operator: Overloads a C++ operator with a new declaration.
  • private: Declares class members who are not visible outside the class.
  • protected: Declares class members who are private except to derived classes
  • public: Declares class members who are visible outside the class.
  • register:A storage class specifier that is an auto specifier, but which also indicates to the compiler that an object will be frequently used and should therefore be kept in a register.
  • goto: This keyword helps to transfer the power of the control to a specified label.
  • if: It indicates the starting point of an if statement to achieve selective control.
  • inline: A function specifier that indicates to the compiler that inline substitution of the function body is to be preferred to the usual function call implementation.
  • int: fundamental data type used to define integer objects.
  • return: Returns an object to a function’s caller.
  • short: A data type modifier that defines a 16-bit int number.
  • signed: A data type modifier that indicates an object’s sign is to be stored in the high-order bit.
  • sizeof: Returns the size of an object in bytes.
  • static: The lifetime of an object-defined static exists throughout the lifetime of program execution.
  • struct: To declare new types that encapsulate both data and member functions.
  • switch: This keyword is used in the switch statement.
  • template: parameterized or generic type.
  • this: A class pointer points to an object or instance of the class.
  • throw: Generate an exception.
  • try: Indicates the start of a block of exception handlers.
  • typedef: Synonym for another integral or user-defined type.
  • union: Similar to a structure, struct, in that it can hold different types of data, but a union can hold only one of its members at a given time.
  • unsigned: A data type modifier that indicates the high-order bit is to be used for an object.
  • virtual: A function specifier that declares a member function of a class that will be redefined by a derived class.
  • void: This keyword identifies the absence of a type or function parameter list.
  • volatile: This particular keyword defines an object that may vary in value in a way that is undetectable to the compiler.
  • while: This keyword helps to start a while statement and end a do...whileloop.

FAQs

1. What are the keywords of C++?

Keywords in C++ are reserved words with specified definitions, such as "if" and "class."

2. How keywords are different from identifiers?

Identifiers are user-defined names for variables, functions, and other things while keywords have predetermined meanings and cannot be used as variable names.

3. How many keywords are there in C++?

32 keywords are available in C++, including "int," "for," "while," and "return."

Summary

In conclusion, C++ keywords are essential language constructs with established meanings. They are essential for program structuring and flow control. In C++ programming, each of the 32 various sorts of keywords, such as "if," "class," and "return," serves a unique purpose. Understanding these keywords is critical for error-free coding. Furthermore, tokens include different aspects of C++ code such as keywords, identifiers, constants, strings, special symbols, & operators, making them the core of C++ programs.

Keywords in C++ |  List of all keywords in C++ ( Full Explanation ) (2024)
Top Articles
Helluva Boss (Insert OC) Moxxie and Millie's Child - Unhappy Campers
Top 7 Best Minion Masters Deck for Beginners (2024) - GameTaco
Www.mytotalrewards/Rtx
San Angelo, Texas: eine Oase für Kunstliebhaber
Kmart near me - Perth, WA
Gamevault Agent
Cad Calls Meriden Ct
Retro Ride Teardrop
Alpha Kenny Buddy - Songs, Events and Music Stats | Viberate.com
Aces Fmc Charting
Pickswise the Free Sports Handicapping Service 2023
Craigslist In Fredericksburg
Big Y Digital Coupon App
Cranberry sauce, canned, sweetened, 1 slice (1/2" thick, approx 8 slices per can) - Health Encyclopedia
Caroline Cps.powerschool.com
Rapv Springfield Ma
What to do if your rotary tiller won't start – Oleomac
Mini Handy 2024: Die besten Mini Smartphones | Purdroid.de
Nene25 Sports
Walmart End Table Lamps
Wisconsin Women's Volleyball Team Leaked Pictures
Brett Cooper Wikifeet
WEB.DE Apps zum mailen auf dem SmartPhone, für Ihren Browser und Computer.
Chelactiv Max Cream
Shasta County Most Wanted 2022
Lcwc 911 Live Incident List Live Status
CDL Rostermania 2023-2024 | News, Rumors & Every Confirmed Roster
Panolian Batesville Ms Obituaries 2022
Black Panther 2 Showtimes Near Epic Theatres Of Palm Coast
Table To Formula Calculator
Truck from Finland, used truck for sale from Finland
Ryujinx Firmware 15
Rugged Gentleman Barber Shop Martinsburg Wv
Redbox Walmart Near Me
Transformers Movie Wiki
Otis Offender Michigan
Ellafeet.official
Solve 100000div3= | Microsoft Math Solver
Joe's Truck Accessories Summerville South Carolina
Darrell Waltrip Off Road Center
Dallas City Council Agenda
Main Street Station Coshocton Menu
18 terrible things that happened on Friday the 13th
“To be able to” and “to be allowed to” – Ersatzformen von “can” | sofatutor.com
Cocaine Bear Showtimes Near Cinemark Hollywood Movies 20
Cuckold Gonewildaudio
Craigslist Com St Cloud Mn
Ups Customer Center Locations
Displacer Cub – 5th Edition SRD
York Racecourse | Racecourses.net
Verilife Williamsport Reviews
Zom 100 Mbti
Latest Posts
Article information

Author: Annamae Dooley

Last Updated:

Views: 6008

Rating: 4.4 / 5 (65 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Annamae Dooley

Birthday: 2001-07-26

Address: 9687 Tambra Meadow, Bradleyhaven, TN 53219

Phone: +9316045904039

Job: Future Coordinator

Hobby: Archery, Couponing, Poi, Kite flying, Knitting, Rappelling, Baseball

Introduction: My name is Annamae Dooley, I am a witty, quaint, lovely, clever, rich, sparkling, powerful person who loves writing and wants to share my knowledge and understanding with you.