| title | Expressions with Unary Operators | Microsoft Docs | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ms.custom | ||||||||||||||
| ms.date | 11/04/2016 | |||||||||||||
| ms.reviewer | ||||||||||||||
| ms.suite | ||||||||||||||
| ms.technology |
|
|||||||||||||
| ms.tgt_pltfrm | ||||||||||||||
| ms.topic | language-reference | |||||||||||||
| dev_langs |
|
|||||||||||||
| helpviewer_keywords |
|
|||||||||||||
| ms.assetid | 1217685b-b85d-4b48-9ff4-d90f56a26c1b | |||||||||||||
| caps.latest.revision | 8 | |||||||||||||
| author | mikeblome | |||||||||||||
| ms.author | mblome | |||||||||||||
| manager | ghogen | |||||||||||||
| translation.priority.ht |
|
Unary operators act on only one operand in an expression. The unary operators are as follows:
These operators have right-to-left associativity. Unary expressions generally involve syntax that precedes a postfix or primary expression.
The following are the possible forms of unary expressions.
-
postfix-expression
-
++unary-expression -
––unary-expression -
unary-operator cast-expression
-
sizeofunary-expression -
sizeof(type-name) -
decltype(expression) -
allocation-expression
-
deallocation-expression
Any postfix-expression is considered a unary-expression, and because any primary expression is considered a postfix-expression, any primary expressions is considered a unary-expression also. For more information, see Postfix Expressions and Primary Expressions.
A unary-operator consists of one or more of the following symbols: * &``+``–``!``~
The cast-expression is a unary expression with an optional cast to change the type. For more information see Cast Operator: ().
An expression can be any expression. For more information, see Expressions.
The allocation-expression refers to the new operator. The deallocation-expression refers to the delete operator. For more information, see the links earlier in this topic.