Javatpoint Logo
Javatpoint Logo

C++ Keywords

C++ keywords play a crucial role in defining the syntax and functioning of the language. They include reserved words with functions, such as specifying data types, managing program flow, and activating additional features. Understanding these terms is essential for good C++ programming and enables programmers to build reliable and adaptable software.

A keyword is a reserved word. You cannot use it as a variable name, constant name etc. A list of 32 Keywords in C++ Language which are also available in C language are given below.

auto break case char const continue default do
double else enum extern float for goto if
int long register return short signed sizeof static
struct switch typedef union unsigned void volatile while

A list of 30 Keywords in C++ Language which are not available in C language are given below.

asm dynamic_cast namespace reinterpret_cast bool
explicit new static_cast false catch
operator template friend private class
this inline public throw const_cast
delete mutable protected true try
typeid typename using virtual wchar_t

Keywords Available in Both C and C++:

Let's discuss these C++ keywords one by one.

auto: In C++, the auto keyword is mainly used for type inference. It enables the compiler to determine a variable's data type from its initializer expression.

break: By using the break keyword, the execution of a loop or switch statement is stopped.

case: It is used in a switch statement to provide several scenarios in which different code blocks should be run depending on the result of an expression.

char: The char keyword is used to declare character variables or data types.

const: Constant values or pointers that refer to constants are declared with the keyword const.

Continue: This keyword is used to go on to the next iteration of a loop without running the last remaining statements.

default: When no other case matches, it is used in a switch statement to provide a default case.

Do: This keyword initiates a loop that runs a series of statements as long as a certain condition is met.

double: Double-precision floating-point variables and data types are declared with the double keyword.

else: It works in conjunction with the if statement to specify an alternative code snippet that is run if the condition is false.

enum: An enumeration is defined by the enum keyword. It is a user-defined type that is made up of a collection of named integer constants.

extern: It is used to declare variables or functions that are declared in another source file.

float: The float keyword is used to declare single-precision floating-point variables or data types.

for: It begins a loop by introducing initialization, condition, and update expressions.

goto: The goto keyword is used to give an unconditional jump from the goto to a labeled statement within the same function.

If: This operator is used to run a block of code only if a certain condition is met.

int: The int keyword is used to declare the integer variables or data types.

long: The long keyword is utilized to declare the integer variables with a wider range than int.

register: The compiler is advised to put the variable in a register for quicker access.

return: This keyword is used to end a function and, if desired, to provide the caller a value back.

short: The short keyword is used to declare an integer short variables.

signed: It is used to declare variables using signed integers.

sizeof: The sizeof keyword is used to calculate the size (in bytes) of a data type or object.

static: The static keyword is used to declare static variables, which keep their values across function calls.

struct: A composite data type with a single name for all its variables is defined with the struct keyword.

switch: It is used to construct a switch statement, which compares an expression to its value and chooses a code block accordingly.

typedef: The typedef keyword is used to give a data type an alias (alternative name).

union: It is used to define a union, which resembles a struct but has one shared memory location for all its members.

Unsigned: The unsigned keyword is used to define unsigned integer variables.

Volatile: This keyword instructs the compiler that a variable's value may change at any point, even if it is not immediately apparent from the logic of the program.

While: This keyword introduces a loop that repeatedly runs a set of statements if a certain condition is met.

Additional C++ Keywords Not Available in C:

Let's discuss some additional C++ keywords one by one.

asm: The asm keyword is used to write programs in assembly language that can be inserted into C++ programs. It enables the writing of inline assembly code by programmers for certain hardware operations.

dynamic_cast: In C++, dynamic type casting uses this keyword. In object-oriented programming, it is mostly used for secure downcasting (from a base class to a derived class) when polymorphism is present.

namespace: The namespace keyword is used to construct a named scope, which aids in organizing and bringing together similar code pieces. It is very helpful in avoiding name disputes.

reinterpret_cast: In C++, this keyword is used to type casting at the lowest level. Without altering the actual data, it may be used to change the type of a pointer to a different type.

bool: The bool keyword is used to define the boolean data type that can only store true or false values. It is frequently employed in conditional statements and logical procedures.

explicit: In C++, the explicit keyword is used to specify that a constructor shouldn't be used automatically to convert types. It reduces the likelihood of accidental automated type conversions.

new: The heap memory is used to dynamically allocate memory for objects during runtime. It gives back a pointer to the RAM that was allotted.

static_cast: In C++, this keyword is utilized for fundamental type casting. It may be used to safely convert between kinds of related types.

false: The boolean value false is represented by the term false. One of C++'s two boolean literals, the other being true.

catch: The catch keyword in exception handling is used to capture and manage errors that the try block throws. It designates a section of code to run in response to a certain exception being thrown.

operator: In C++, standard operators can be overloaded to operate with user-defined types by using the operator keyword. It permits the development of unique operator behavior.

template: By parameterizing types and functions, templates are defined by the template keyword, enabling generic programming. Templates provide for flexibility and reuse of code.

friend: A class or function is designated as a friend of another class using the friend keyword. Friends have access to their classmate's private information and protected information.

private: The access level of class members is specified using the private keyword. Only the class itself has access to private members.

class: In C++, a class is defined with the class keyword. A user-defined data type called a class that contains both data and functions.

this: It is a reference to the current instance of a class that is referred to by the term. Within its member functions, it is utilized to access members of the class.

inline: The inline keyword is used to instruct the compiler to expand a function inline. As a result, the performance can be increased by lowering function call overhead.

public: The access level of class members is specified with the public keyword. Access to public members is available during the whole program.

throw: The throw keyword is used to manually throw an exception in C++. It is a crucial component of the C++ exception-handling system.

const_cast: This keyword is used to remove a variable's const-ness. It mostly serves to change a variable's type qualifiers.

delete: The memory that was previously allocated using the new keyword is released with the delete keyword. Memory leaks must be avoided at all costs.

Mutable: In C++, the mutable keyword is used to denote the ability to change a member of a const object. It is frequently employed when member variables within const member functions need to be updated.

protected: The protected keyword is used to specify the access level of class members. Accessible inside the class and classes descended from it are protected members.

truth: The word "true" stands for the boolean value "true". Along with false, it is one of the two boolean literals in C++.

try: In exception handling, the try keyword is used to surround a block of code that may throw exceptions. One or more catch blocks are placed after it to deal with certain exceptions.

typeid: The typeid keyword is used to learn more about an expression's type. It is frequently employed for runtime type identification.

typename: In templates, you may use the typename keyword to indicate that a dependent name is a type. When dealing with template metaprogramming, it is frequently employed.

using: Namespace aliasing, template specialization, and declarations all make use of the keyword. It facilitates namespace management and increases code readability.

virtual: The terms inheritance and polymorphism are used together to describe the concept of virtual. It designates a member function as virtual so that descendant classes may override it.

Wchar_t: A wide character data type that can store expanded character sets and support internationalization is defined by the wchar_t keyword.

Conclusion:

In conclusion, for every programmer looking to unlock the full potential of this flexible programming language, knowing the importance and utilization of keywords in C++ is crucial. These keywords cover a wide range of capabilities, including memory management, type declarations, control flow, and data manipulation.

The C++ language's unique keywords are equally significant, which introduce cutting-edge features and paradigms and elevate C++ above its C roots. By enhancing the possibilities of C++, these keywords let developers explore ideas like object-oriented programming, templates, exception handling, type casting, and more. Developers may design modular, effective, and expressive codebases with the use of terms like "namespace", "operator", "template", and "dynamic_cast".

Programmers may write code that is not only functional but also effective, manageable, and flexible by mastering these terms. It gives them the ability to create sophisticated software systems, employ challenging techniques, and develop beautiful answers to a variety of computational problems. Additionally, as C++ develops further, the set of keywords may grow, giving developers access to even more potent instruments.

In C++, keywords serve as the fundamental building blocks that allow developers to translate abstract ideas into executable code. They give programmers the tools to handle data, manage program flow, and produce abstractions, which makes software development more effective and well-structured. Unlocking the full potential of C++ programming and creating powerful, feature-rich programs require a thorough grasp of these linguistic components, whether it is through utilizing the fundamental keywords shared with C or utilizing the creativity of C++ exclusive keywords.


Next TopicC++ Operators





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA