Punctuation
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
C++ language
General topics
Conditional execution statements
Iteration statements (loops)
Jump statements
Dynamic exception specifications (until C++17*)
noexcept
specifier (C++11) Exceptions
Namespaces
Types
Specifiers
User-defined (C++11)
Utilities
Attributes (C++11)
Types
Type alias declaration (C++11)
Casts
Memory allocation
Class-specific function properties
Special member functions
Miscellaneous
Basic Concepts
These are the punctuation symbols in C++. The meaning of each symbol is detailed in the linked pages.
Contents
- 1 Preprocessing operators
- 2 Single-character operators and punctuators
- 3 Multi-character operators and punctuators
- 3.1 ...
- 3.2 ::
- 3.3 .*
- 3.4 ->
- 3.5 ->*
- 3.6 +=
- 3.7 -=
- 3.8 *=
- 3.9 /=
- 3.10 %=
- 3.11 ^= (including xor_eq)
- 3.12 &= (including and_eq)
- 3.13 |= (including or_eq)
- 3.14 ==
- 3.15 != (including not_eq)
- 3.16 <=
- 3.17 >=
- 3.18 <=>
- 3.19 && (including and)
- 3.20 || (including or)
- 3.21 <<
- 3.22 >>
- 3.23 <<=
- 3.24 >>=
- 3.25 ++
- 3.26 --
- 4 References
- 5 See also
[edit] Preprocessing operators
Preprocessing operators are recognized by preprocessors.
[edit] # (including %:)
- Introduce a preprocessing directive.
- The preprocessing operator for stringification.
[edit] ##(including %:%:)
[edit] Single-character operators and punctuators
[edit] { and } (including <% and %>)
- In a class definition, delimit the member specification.
- In an enumeration definition, delimit the enumerator list.
- Delimit a compound statement. The compound statement may be part of
(since C++11)
- Part of the aggregate initialization (until C++11)list-initialization (since C++11) syntax of an initializer.
- In a namespace definition, delimit the namespace body.
- In a language linkage specification, delimit the declarations.
- In a requires expression, delimit the requirements.
- In a compound requirement, delimit the expression.
- In an export declaration, delimit the declarations.
[edit] [ and ] (including <: and :>)
- Subscript operator; part of operator[] in operator overloading.
- Part of array declarator in a declaration or a type-id (e.g. in a new expression).
- Part of new[] operator in operator overloading (allocation function).
- Part of delete[] operator in delete expression and operator overloading (deallocation function).
- In a lambda expression, delimit the captures.
- In an attribute specifier, delimit the attributes.
- In a structured binding declaration, delimit the identifier list.
- In a pack indexing, delimit converted constant expression representing an index.
[edit] ( and )
- In an expression, indicate grouping.
- Function call operator; part of operator() in operator overloading.
- In a function-style type cast, delimit the expression/initializers.
- In a
static_cast
,const_cast
,reinterpret_cast
, ordynamic_cast
, delimit the expression. - Delimit the operand of the following operators:
- In a placement new expression, delimit the placement arguments.
- In a new expression, optionally delimit the type-id.
- In a new expression, delimit the initializers.
- In a C-style cast, delimit the type-id.
- In a declaration or a type-id, indicate grouping.
- Delimit the parameter list in
- a function declarator (in a declaration or a type-id)
(since C++11)
(since C++17)
(since C++20)
- Part of the direct-initialization syntax of an initializer.
- In an asm declaration, delimit the string literal.
- In a member initializer list, delimit the initializers to a base or member.
- Delimit the controlling clause of a selection statement or iteration statement, including:
(since C++11)
- In a handler, delimit the parameter declaration.
- In a function-like macro definition, delimit the macro parameters.
- In a function-like macro invocation, delimit the macro arguments or prevent commas from being interpreted as argument separators.
- Part of a
defined
,__has_include
(since C++17),__has_cpp_attribute
(since C++20) preprocessing operator.
- In a
static_assert
declaration, delimit the operands. - Delimit the operand of the following specifiers:
(since C++20)
- In an attribute, delimit the attribute arguments.
- Part of
decltype(auto)
specifier.
- Delimit a fold expression.
- Part of __VA_OPT__ replacement in a variadic macro definition.
[edit] ;
- Indicate the end of
- a module declaration, import declaration, global module fragment introducer, or private module fragment introducer
- a requirement
- Separate the condition and statement of a for statement.
[edit] :
- Part of conditional operator.
- Part of label declaration.
- In the base-clause of a class definition, introduce the base class.
- Part of access specifier in member specification.
- In a bit-field member declaration, introduce the width.
- In a constructor definition, introduce the member initializer list.
- In a range-based for statement, separate the item-declaration and the range-initializer.
- In the enum-base of an enumeration declaration, introduce the underlying type.
- In an attribute specifier, separate the attribute-namespace and the attribute-list.
- In a module declaration or import declaration of module partition, introduce the module partition name.
- Part of a private module fragment introducer (module :private;).
[edit] ?
- Part of conditional operator.
[edit] .
- In aggregate initialization, introduce a designator.
- Part of module name or module partition name.
[edit] ~ (including compl)
- Unary complement operator (a.k.a. bitwise not operator); part of operator~ in operator overloading.
- Part of an identifier expression to name a destructor or pseudo-destructor.
[edit] ! (including not)
- Logical not operator; part of operator! in operator overloading.
- Part of consteval if statement.
[edit] +
- Unary plus operator; part of operator+ in operator overloading.
- Binary plus operator; part of operator+ in operator overloading.
[edit] -
- Unary minus operator; part of operator- in operator overloading.
- Binary minus operator; part of operator- in operator overloading.
[edit] *
- Indirection operator; part of operator* in operator overloading.
- Multiplication operator; part of operator* in operator overloading.
- Pointer operator or part of pointer-to-member operator in a declarator or in a type-id.
- Part of *this in a lambda capture list, to capture the current object by copy.
[edit] /
- Division operator; part of operator/ in operator overloading.
[edit] %
- Modulo operator; part of operator% in operator overloading.
[edit] ^ (including xor)
- Bitwise xor operator; part of operator^ in operator overloading.
[edit] & (including bitand)
- Address-of operator; part of operator& in operator overloading.
- Bitwise and operator; part of operator& in operator overloading.
- Lvalue-reference operator in a declarator or in a type-id.
- In a lambda capture, indicate by-reference capture.
- Ref-qualifier in member function declaration.
[edit] | (including bitor)
- Bitwise or operator; part of operator| in operator overloading.
[edit] =
- Simple assignment operator; part of operator= in operator overloading, which might be a special member function (copy assignment operator or move assignment operator (since C++11)).
- Part of the copy-initialization and aggregate initialization (until C++11)copy-list-initialization (since C++11) syntax of an initializer.
- In a function declaration, introduce a default argument.
- In a template parameter list, introduce a default template argument.
- In a namespace alias definition, separate the alias and the aliased namespace.
- In an enum definition, introduce the value of enumerator.
- Part of pure-specifier in a pure virtual function declaration.
- Capture default in lambda capture, to indicate by-copy capture.
- Part of defaulted definition (=default;) or deleted definition (=delete;) in function definition.
- In a type alias declaration, separate the alias and the aliased type.
- In a concept definition, separate the concept name and the constraint expression.
[edit] <
- Less-than operator; part of operator< in operator overloading.
- In a
static_cast
,const_cast
,reinterpret_cast
, ordynamic_cast
, introduce the type-id. - Introduce a template argument list.
- Introduce a template parameter list in
(since C++20)
- Part of template<> in template specialization declaration.
- Introduce a header name in
(since C++17)
(since C++20)
[edit] >
- Greater-than operator; part of operator> in operator overloading.
-
static_cast
,const_cast
,reinterpret_cast
, ordynamic_cast
, indicate the end of type-id. - Indicate the end of a template argument list.
- Indicate the end of a template parameter list in
(since C++20)
- Part of template<> in template specialization declaration.
- Indicate the end of a header name in
(since C++17)
(since C++20)
[edit] ,
- Comma operator; part of operator, in operator overloading.
- List separator in
- the declarator list in a declaration
- initializer list in initialization
- the placement argument list in a placement new
- the argument list in a function call expression
- the enumerator list in an enum declaration
- the base class list in a class declaration
- the member initializer list in a constructor definition
- a function parameter list
- a template parameter list
- a template argument list
- a lambda capture list
- an attribute list
- the declarator list in a using-declaration
- the identifier list in a structured binding declaration
- the argument list in a multi-argument subscript expression
- the macro parameter list in a function-like macro definition
- the macro argument list in a function-like macro invocation, unless found between the parentheses of an argument
- In a
static_assert
declaration, separate the arguments.
[edit] Multi-character operators and punctuators
[edit] ...
- In the parameter list of a function declaratoror lambda expression(since C++11)or user-defined deduction guide(since C++17), signify a variadic function.
- In a handler, signify catch-all handler.
- In a macro definition, signify a variadic macro.
- Indicate pack declaration and expansion.
- In pack indexing expression and specifier.
[edit] ::
- Scope resolution operator in
- a qualified name
- a pointer-to-member declaration
- a
new
ordelete
expression, to indicate that only global allocation or deallocation functions are looked up
- In an attribute, indicate attribute scope.
- Part of nested namespace definition.
[edit] .*
[edit] ->
- Member access operator; part of operator-> in operator overloading.
- In a function declarator or lambda expression, introduce the trailing return type.
- In a user-defined deduction guide, introduce the result type.
- In a compound requirement, introduce the return type requirement.
[edit] ->*
- Pointer-to-member access operator; part of operator->* in operator overloading.
[edit] +=
- Compound assignment operator; part of operator+= in operator overloading.
[edit] -=
- Compound assignment operator; part of operator-= in operator overloading.
[edit] *=
- Compound assignment operator; part of operator*= in operator overloading.
[edit] /=
- Compound assignment operator; part of operator/= in operator overloading.
[edit] %=
- Compound assignment operator; part of operator%= in operator overloading.
[edit] ^= (including xor_eq)
- Compound assignment operator; part of operator^= in operator overloading.
[edit] &= (including and_eq)
- Compound assignment operator; part of operator&= in operator overloading.
[edit] |= (including or_eq)
- Compound assignment operator; part of operator|= in operator overloading.
[edit] ==
- Equality operator; part of operator== in operator overloading.
[edit] != (including not_eq)
- Inequality operator; part of operator!= in operator overloading.
[edit] <=
- Less-than-or-equal-to operator; part of operator<= in operator overloading.
[edit] >=
- Greater-than-or-equal-to operator; part of operator>= in operator overloading.
<=>
- Three-way comparison (spaceship) operator; part of operator<=> in operator overloading.
[edit] && (including and)
- Logical and operator; part of operator&& in operator overloading.
- Rvalue-reference operator in a declarator or in a type-id.
- Ref-qualifier in member function declaration.
[edit] || (including or)
- Logical or operator; part of operator|| in operator overloading.
[edit] <<
- Bitwise shift operator; part of operator<< in operator overloading (bitwise operator or stream insertion operator).
[edit] >>
- Bitwise shift operator; part of operator>> in operator overloading (bitwise operator or stream extraction operator).
[edit] <<=
- Compound assignment operator; part of operator<<= in operator overloading.
[edit] >>=
- Compound assignment operator; part of operator>>= in operator overloading.
[edit] ++
- Increment operator; part of operator++ in operator overloading.
[edit] --
- Decrement operator; part of operator-- in operator overloading.
[edit] References
- C++23 standard (ISO/IEC 14882:2024):
- 5.12 Operators and punctuators [lex.operators]
- C++20 standard (ISO/IEC 14882:2020):
- 5.12 Operators and punctuators [lex.operators]
- C++17 standard (ISO/IEC 14882:2017):
- 5.12 Operators and punctuators [lex.operators]
- C++14 standard (ISO/IEC 14882:2014):
- 2.13 Operators and punctuators [lex.operators]
- C++11 standard (ISO/IEC 14882:2011):
- 2.13 Operators and punctuators [lex.operators]
- C++03 standard (ISO/IEC 14882:2003):
- 2.12 Operators and punctuators [lex.operators]
- C++98 standard (ISO/IEC 14882:1998):
- 2.12 Operators and punctuators [lex.operators]
[edit] See also
Alternative representations
alternative spellings for certain operators[edit]
C documentation for Punctuation