Namespaces
Variants
Actions

C++ language

From cppreference.com
 
 
C++ language
General topics
Flow control
Conditional execution statements
if
Iteration statements (loops)
for
range-for (C++11)
Jump statements
Functions
Function declaration
Lambda function expression
inline specifier
Dynamic exception specifications (until C++17*)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
Specifiers
const/volatile
decltype (C++11)
auto (C++11)
constexpr (C++11)
consteval (C++20)
constinit (C++20)
Storage duration specifiers
Initialization
Expressions
Alternative representations
Literals
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
typedef declaration
Type alias declaration (C++11)
Casts
Memory allocation
Classes
Class-specific function properties
explicit (C++11)
static

Special member functions
Templates
Miscellaneous
 

This is a brief reference of available C++ language constructs.

Contents

General topics

Preprocessor

Comments

Keywords

ASCII chart

Escape sequences

History of C++

Basic definitions

Flow control

Conditional execution statements

Conditional statements execute different code paths according to the value of given expression.

  • if executes code conditionally
  • switch executes code according to the value of an integral argument

Iteration statements

Iteration statements execute a code path multiple times.

  • for executes loops by specifying initialization, comparison, and increment
  • range-for executes loops over a range (since C++11)
  • while executes loop, checking condition before each iteration
  • do-while executes loop, checking condition after each iteration

Jump statements

Jump statements continue program execution at a different location.

  • continue skips the remaining part of the enclosing loop body
  • break terminates the enclosing loop
  • goto continues execution in another location
  • return terminates execution of the enclosing function

Functions

The same code can be reused at different locations in the program.

Exceptions

Exceptions are a more robust way to signal error condition than function return codes or global error variables.

Namespaces

Namespaces provide a way to prevent name clashes in large projects.

Types

  • fundamental types define basic character, integer and floating point types
  • pointer types define types holding a memory location
  • compound types define types that hold several data members (essentially the same as class)
  • enumeration types define types that are able to hold only one of the specified values
  • union types define types that can hold data in several representations
  • function types define function call signatures, that is the types of arguments and the return type
  • decltype specifier defines a type equivalent to the type of an expression (since C++11)

Specifiers

Initialization

Whenever a named variable is declared, and whenever a temporary object is created, the initial value of the new object is provided through one of the following mechanisms:

Literals

Literals are the tokens of a C++ program that represent constant values, embedded in the source code.

Expressions

An expression is a sequence of operators and operands that specifies a computation. An expression can result in a value and can cause side effects.

  • value categories (lvalue, rvalue, glvalue, prvalue, xvalue) classify expressions by their values
  • order of evaluation of arguments and subexpressions specify the order in which intermediate results are obtained
  • operators allow the use of syntax commonly found in mathematics
Common operators
assignment increment
decrement
arithmetic logical comparison member
access
other

a = b
a += b
a -= b
a *= b
a /= b
a %= b
a &= b
a |= b
a ^= b
a <<= b
a >>= b

++a
--a
a++
a--

+a
-a
a + b
a - b
a * b
a / b
a % b
~a
a & b
a | b
a ^ b
a << b
a >> b

!a
a && b
a || b

a == b
a != b
a < b
a > b
a <= b
a >= b
a <=> b

a[...]
*a
&a
a->b
a.b
a->*b
a.*b

function call
a(...)
comma
a, b
conditional
a ? b : c
Special operators

static_cast converts one type to another related type
dynamic_cast converts within inheritance hierarchies
const_cast adds or removes cv-qualifiers
reinterpret_cast converts type to unrelated type
C-style cast converts one type to another by a mix of static_cast, const_cast, and reinterpret_cast
new creates objects with dynamic storage duration
delete destructs objects previously created by the new expression and releases obtained memory area
sizeof queries the size of a type
sizeof... queries the size of a parameter pack (since C++11)
typeid queries the type information of a type
noexcept checks if an expression can throw an exception (since C++11)
alignof queries alignment requirements of a type (since C++11)

Utilities

Types
Casts
Memory allocation

Classes

Classes provide the concept of object-oriented programming in C++.

Class-specific function properties

Special member functions

Templates

Allows functions and classes to operate on generic types

Start and termination

Optimizations

  • the as-if rule allows any code transformation that doesn't change the output
  • copy elision, including RVO and NRVO, makes pass-by-value the preferred approach in many situations.
  • empty base optimization makes multiple inheritance from interfaces or policy classes overhead-free and is required for standard-layout types.

Miscellaneous