Namespaces
Variants
Views
Actions

C++ language

From cppreference.com
< cpp
 
 
C++ language
General topics
Preprocessor
Comments
Keywords
ASCII chart
Escape sequences
History of C++
Flow control
Conditional execution statements
Iteration statements
Jump statements
Functions
function declaration
lambda function declaration
function template
inline specifier
exception specifications (deprecated)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
decltype specifier (C++11)
Specifiers
cv specifiers
storage duration specifiers
constexpr specifier (C++11)
auto specifier (C++11)
alignas specifier (C++11)
Literals
Expressions
alternative representations
Utilities
Types
typedef declaration
type alias declaration (C++11)
attributes (C++11)
Casts
implicit conversions
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-style and functional cast
Memory allocation
Classes
Class-specific function properties
Special member functions
Templates
class template
function template
template specialization
parameter packs (C++11)
Miscellaneous
Inline assembly
 

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

Contents

[edit] General topics

[edit] Preprocessor

[edit] Comments

[edit] Keywords

[edit] ASCII chart

[edit] Escape sequences

[edit] History of C++

[edit] Flow control

[edit] 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

[edit] 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

[edit] 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

[edit] Functions

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

[edit] Exceptions

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

[edit] Namespaces

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

[edit] 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)

[edit] Specifiers

[edit] Literals

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

[edit] 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 = rvalue
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->b
a.b
a->*b
a.*b

a(...)
a, b
(type) a
? :

Special operators

static_cast converts one type to another compatible type
dynamic_cast converts virtual base class to derived class
const_cast converts type to compatible type with different cv qualifiers
reinterpret_cast converts type to incompatible type
new allocates memory
delete deallocates memory
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)

[edit] Utilities

Types
Casts
Memory allocation

[edit] Classes

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

[edit] Class-specific function properties

[edit] Special member functions

[edit] Templates

Allows functions and classes to operate on generic types

[edit] Miscellaneous