C++ Keywords

Reserved keywords & their meanings.

Reserved Keywords

Reserved keywords are words that have special meaning and are reserved for specific purposes. These keywords cannot be used as identifiers (names for variables, functions, classes, etc.) because they are already used by the language for specific tasks. Here's a list of reserved keywords in C++:

  • asm
  • auto
  • break
  • case
  • catch
  • char
  • class
  • const
  • continue
  • default
  • delete
  • do
  • double
  • else
  • enum
  • extern
  • float
  • for
  • friend
  • goto
  • if
  • inline
  • int
  • long
  • new
  • operator
  • private
  • protected
  • public
  • register
  • return
  • short
  • signed
  • sizeof
  • static
  • struct
  • switch
  • template
  • this
  • throw
  • try
  • typedef
  • union
  • unsigned
  • virtual
  • void
  • volatile
  • while
asm auto break case catch
char class const continue default
delete do double else enum
extern float for friend goto
if inline int long new
operator private protected public register
return short signed sizeof static
struct switch template this throw
try typedef union unsigned virtual
void volatile while

Note: Please note that some keywords, like 'char8_t', 'char16_t', and 'char32_t' are introduced for Unicode character types in C++11. The list may be subject to changes with new C++ standards.

Essential keywords with their meanings:

  1. 'asm': To declare that a block-of-code is to be passed to the assembler.

  2. 'auto': Specifies automatic type deduction for variables declared with it.

  3. 'break': Used to terminate a loop or switch statement.

  4. 'case': Used in a switch statement to define different possible values.

  5. 'catch': Specifies actions taken when an exception occurs.

  6. 'char': Declares a character type.

  7. 'class': Declares a class in object-oriented programming.

  8. 'const': Specifies that a variable's value cannot be changed.

  9. 'continue': Jumps to the next iteration of a loop.

  10. 'default': Specifies the default case in a switch statement.

  11. 'delete': Used to deallocate memory that was previously allocated with 'new'.

  12. 'do': Initiates a do-while loop.

  13. 'double': Declares a double-precision floating-point type.

  14. 'else': Used in conjunction with if statements to specify the code to execute when the condition is false.

  15. 'enum': Declares an enumeration type.

  16. 'extern': Declares that a variable or function is defined elsewhere.

  17. 'float': Declares a floating-point type.

  18. 'for': Initiates a for loop.

  19. 'friend': Declares a function or class as a friend, allowing it to access private members of another class.

  20. 'goto': Transfer control to a specified label..

  21. 'if': Initiates an if statement.

  22. 'inline': Suggests the compiler to insert the code of the function into the calling code rather than generating a function call.

  23. 'int': Declares an integer type.

  24. 'long': Declares a long integer type.

  25. 'new': Allocates memory for an object or an array.

  26. 'operator': Declares an operator function.

  27. 'private': Specifies that class members declared as private are accessible only within the same class.

  28. 'protected': Specifies that class members declared as protected are accessible within the same class and its subclasses.

  29. 'public': Specifies that class members declared as public are accessible from anywhere.

  30. 'register': Suggests to the compiler that a variable should be stored in a register.

  31. 'return': Specifies the return value of a function.

  32. 'short': Declares a short integer type.

  33. 'signed': Declares a signed integer type.

  34. 'sizeof': Returns the size, in bytes, of a type or an object.

  35. 'static': Specifies that a variable or function is static, meaning it has a single instance shared by all instances of the class or function.

  36. 'struct': Declares a structure, a composite data type.

  37. 'switch': Initiates a switch statement.

  38. 'template': Declares a template, a way to write generic code.

  39. 'this': A pointer that points to the object for which the member function is called.

  40. 'throw': Signals that an exception has occurred.

  41. 'try': Initiates a block of code that may throw an exception.

  42. 'typedef': Creates a type alias.

  43. 'union': Declares a union, a type that can hold different data types but only one at a time.

  44. 'unsigned': Declares an unsigned integer type.

  45. 'virtual': Specifies that a function can be overridden in derived classes.

  46. 'void': Specifies that a function does not return a value or that a pointer does not point to any type.

  47. 'volatile': Indicates that a variable may be changed by multiple threads or asynchronously.

  48. 'while': Start of a while statement and end of a do-while statement.

These keywords are fundamental to writing C++ code, and understanding their usage is crucial for developing effective and efficient programs.

What's Next?

We actively create content for our YouTube channel and consistently upload or share knowledge on the web platform.