c++ Keyword Summary

Keyword Summary 

Overview

The C89 language defines the following 32 keywords.
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

C++ includes all keywords defined by C89 and adds the following:

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

Older versions of C++ also defined the overload keyword, but it is obsolete.
C99 includes all of the keywords defined by C89 and adds the following:
_Bool
_Complex
_Imaginary
inline
restrict
A brief synopsis of the keywords follows.

asm

asm is used to embed assembly language directly into your C++ program. The general form of the asm statement is shown here:
asm ("instruction");
Here, instruction is an assembly language instruction, which is passed directly to the compiler for assembly in your program.
Many C++ compilers allow additional forms of the asm statement. For example,
asm instruction;
asm {
    instruction sequence
}
Here, instruction sequence is a list of assembly language instructions.

auto

auto declares local variables. It is completely optional and seldom used.

bool

The type specifier bool is used to declare Boolean (i.e., true/false) values.

_Bool

C99 includes the _Bool data type, which is capable of storing the values 1 and 0 (i.e., true/false). _Bool is an integer type, and it differs from the C++ keyword bool. Thus, C99 and C++ are incompatible on this point. Also, C++ defines the built-in Boolean constants true and false, but C99 does not. However, C99 adds the header <stdbool.h>, which defines the macros bool, true, and false. Thus, C/C++-compatible code can be easily created.
The reason that _Bool rather than bool was specified as a keyword is that many existing C programs had already defined their own custom versions of bool. By defining the Boolean type as _Bool, C99 avoids breaking this preexisting code. However, for new C programs, it is best to include <stdbool.h> and then use the bool macro.

break

break is used to exit from a do, for, or while loop, bypassing the normal loop condition. It is also used to exit from a switch statement.
An example of break in a loop is shown here:
do {
  x = getx();
  if(x < 0) break; // terminate if negative 
  process(x);
} while(!done);
 
Here, if x is negative, the loop is terminated.
In a switch statement, break keeps program execution from “falling through” to the next case. (Refer to the switch statement for details.)
A break terminates only the for, do, while, or switch that contains it. It will not break out of any nested loops or switch statements

case

The case statement is used with a switch statement. See switch.

catch

The catch statement handles an exception generated by throw. See throw.

char

char is a data type used to declare character variables.

class

class is used to declare classes—C++’s basic unit of encapsulation. Its general form is shown here:
class class-name : inheritance-list {
    // private members by default
protected:
    // private members that can be inherited
public:
    // public members
} object-list;
Here, class-name is the name of the new data type being generated by the class declaration. The inheritance-list, which is optional, specifies any base classes inherited by the new class. By default, members of a class are private. They may be made protected or public through the use of the protected and public keywords, respectively.
The object-list is optional. If not present, a class declaration simply specifies the form of a class. It does not create any objects of the class.

Note 
For additional information on class,

_Complex

C99 includes the keyword _Complex, which supports complex arithmetic. The following _Complex types are defined:
float _Complex
double _Complex
long double _Complex
The reason that _Complex, rather than complex, was specified as a keyword is that many existing C programs had already defined their own custom complex data types using the name complex. By defining the keyword _Complex, C99 avoids breaking this preexisting code.
The header <complex.h> defines (among other things) the macro complex, which expands to _Complex. Thus, for new C programs, it is best to include <complex.h> and then use the complex macro.

const_cast

The const_cast operator is used to explicitly override const and/or volatile in a cast. It has this general form:
const_cast<type> (expr)
The target type must be the same as the source type except for the alteration of its const or volatile attributes. The most common use of const_cast is to remove constness.

continue

continue is used to bypass portions of code in a loop and forces the conditional expression to be evaluated. For example, the following while loop reads characters from the keyboard until an s is typed:
while(ch = getchar()) {
  if(ch != 's') continue;  // read another char 
  process(ch);
}
 
The call to process( ) will not occur until ch contains the character s.

default

default is used in the switch statement to signal a default block of code to be executed if no matching case statement is found in the switch. See switch.

delete

The delete operator frees the memory pointed to by its argument. This memory must have previously been allocated using new. The general form of delete is
delete p_var;
where p_var is a pointer to previously allocated memory.
To free an array that has been allocated using new, use this general form of delete:
delete [ ] p_var;

do

The do loop is one of three loop constructs available in C++. The general form of the do loop is
do {
     statement block
} while(condition);
If only one statement is repeated, the braces are not necessary, but they add clarity to the statement.
The do loop is the only loop in C/C++ that will always have at least one iteration because the condition is tested at the bottom of the loop.

Followers