Types of Expressions

Primary Expressions A primary expression can be any of the following:
  • identifier
  • a qualified class name
  • string literal
  • parenthesized expression
  • constant expression
  • function call
  • array element specification
  • structure of union member specification
  • a runtime type identification (RTTI) expression

All primary operators have the same precedence, and have left-to-right associativity.

Unary Expressions A unary expression contains one operand and a unary operator.

All unary operators have the same precedence, and have right-to-left associativity. The usual arithmetic conversions are performed on the operands of most unary expressions.

Binary Expressions A binary expression contains two operands separated by one operator.

Not all binary operators have the same precedence. All binary operators have left-to-right associativity. The usual arithmetic conversions are performed on the operands of most binary expressions.

The order in which the operands of most binary operators are evaluated is not specified. To ensure correct results, avoid creating binary expressions that depend on the order in which the compiler evaluates the operands.

Conditional Expressions A conditional expressions is a compound expression that contains a condition (operand1), an expression to be evaluated if the condition has a non-zero value (operand2), and an expression to be evaluated if the condition has the value 0 (operand3).

Conditional expressions have right-to-left associativity. The left operand (operand1) is evaluated first, and then only one of the two remaining operands is evaluated. If that operand's expression contains or returns arithmetic types, the usual arithmetic conversions are performed on that expression's values.

Assignment Expressions An assignment expression stores a value in the object designated by the left operand. There are two types of assignment operators: simple assignment, and compound assignment.

The left operand in all assignment expressions must be a modifiable lvalue. The type of the expression is the type of the left operand. The value of the expression is the value of the left operand after the assignment completes. The result of an assignment expression is not an lvalue.

All assignment operators have the same precedence, and have right-to-left associativity.

Comma Expression A comma expression contains two operands separated by a comma. Although the compiler evaluates both operands, the value of the right operand is the value of the expression. The left operand is evaluated, possibly producing side effects, and the value is discarded. The result of a comma expression is not an lvalue.

Both operands of a comma expression can have any type. All comma expressions have left-to-right associativity. The left operand is fully evaluated before the right operand.

 



Operator Precedence and Associativity
Operands
lvalues
Constant Expressions
Function Calls


Expressions
Operator Precedence and Associativity Table
Primary Operators
Unary Operators
Binary Operators
Conditional Operator
Assignment Operators
Comma Operator