C++ Keywords

In C++, keywords are reserved words that have special meanings and cannot be used as identifiers (such as variable names or function names). These keywords define the syntax and structure of the C++ language. Understanding these keywords is fundamental for effective programming in C++.

Keywords in C++ Language which are also available in C language

Keyword Description
auto Automatically deduces the type of a variable from its initializer.
break Exits from the innermost loop or switch statement.
case Specifies a branch in a switch statement.
char Defines a character data type.
const Defines constant variables whose values cannot be changed.
continue Skips the remaining code in the current iteration of a loop and proceeds to the next iteration.
default Specifies the default case in a switch statement.
do Starts a do-while loop that executes at least once.
double Defines a double-precision floating-point variable.
else Specifies a block of code to execute if the if condition is false.
enum Defines a set of named integer constants.
extern Declares variables or functions that are defined in another file.
float Defines a single-precision floating-point variable.
for Starts a for loop, which is used for iteration.
goto Transfers control to a labeled statement within the same function.
if Executes a block of code if a condition is true.
int Defines an integer data type.
long Defines a long integer type, typically larger than int.
register Suggests that the variable be stored in a CPU register for faster access.
return Exits a function and optionally returns a value to the caller.
short Defines a short integer type, typically smaller than int.
signed Specifies that an integer type can hold both positive and negative values.
sizeof Returns the size (in bytes) of a data type or object.
static Defines static variables that retain their value between function calls.
struct Defines a composite data type composed of multiple variables.
switch Allows branching based on the value of an expression.
typedef Creates an alias for a data type.
union Defines a union, a data structure where all members share the same memory location.
unsigned Specifies that an integer type can only hold non-negative values.
volatile Indicates that a variable's value may be changed by something outside the control of the code section.
void Specifies that a function does not return a value or that a pointer has no type.
while Starts a while loop that continues as long as a condition is true.

Keywords in C++ Language which are not available in C language

Keyword Description
asm Allows embedding assembly language instructions directly within C++ code.
dynamic_cast Safely casts a pointer or reference to a base class to a pointer or reference to a derived class.
namespace Declares a scope that holds identifiers (like classes, objects, and functions) to avoid name conflicts.
reinterpret_cast Converts any pointer type to any other pointer type, even of unrelated classes.
bool Defines a boolean data type that can hold true or false.
explicit Prevents implicit type conversion by marking constructors as explicit.
new Allocates memory on the heap for an object or array and returns a pointer to it.
static_cast Safely converts between related types, such as pointers to base and derived classes.
false Represents the boolean value false.
catch Catches and handles exceptions thrown by try blocks.
operator Overloads operators for user-defined types to give them custom behavior.
template Allows the creation of generic functions or classes that work with any data type.
friend Grants a function or another class access to the private and protected members of the class.
private Specifies that members of a class are accessible only within the class itself.
class Defines a new user-defined type (a class) that can contain data and functions.
this Refers to the current instance of a class within its member functions.
inline Suggests to the compiler to expand a function inline to reduce the overhead of a function call.
public Specifies that members of a class are accessible from outside the class.
throw Throws an exception that can be caught by a catch block.
const_cast Casts away the const-ness of variables, allowing modification of a const variable.
delete Deallocates memory that was previously allocated with new.
mutable Allows a member of a struct or class to be modified even if the object is const.
protected Specifies that members of a class are accessible within the class and by derived classes.
true Represents the boolean value true.
try Starts a block of code that may throw an exception, which can be caught by a catch block.
typeid Allows runtime type identification (RTTI) to determine the type of an object at runtime.
typename Indicates that a dependent name in a template is a type.
using Brings a name from a namespace into the current scope, or defines an alias for a type.
virtual Allows derived classes to override a member function of a base class.
wchar_t Defines a wide character type that can represent larger character sets, such as Unicode.

Conclusion

This conclusion highlights the importance of understanding C++ keywords for programmers who want to maximize the language's potential. It underscores how these keywords enable a wide range of programming capabilities, from basic data manipulation and control flow to more advanced concepts like object-oriented programming, templates, and exception handling. By mastering these keywords, developers can write code that is both powerful and efficient, leading to the creation of sophisticated, flexible, and maintainable software systems.

Moreover, the conclusion points out that C++'s unique keywords, which differentiate it from C, introduce advanced features that elevate the language. These keywords empower developers to explore new paradigms, such as modular programming and type casting, allowing them to craft more expressive and dynamic codebases.

The final takeaway is that as C++ continues to evolve, its set of keywords may expand, offering even more powerful tools for developers. Understanding and effectively using these keywords are essential for translating abstract concepts into executable code, ultimately leading to the development of robust and feature-rich programs.