Expressions (C++)
Go Up to Expressions Index
An expression is a sequence of operators, operands, and punctuators that specifies a computation. The formal syntax, listed in C++Builder expressions, indicates that expressions are defined recursively: subexpressions can be nested without formal limit. (However, the compiler will report an out-of-memory error if it can't compile an expression that is too complex.)
Note: C++Builder expressions show how identifiers and operators are combined to form grammatically legal "phrases".
Expressions are evaluated according to certain conversion, grouping, associativity, and precedence rules that depend on the operators used, the presence of parentheses, and the data types of the operands. The standard conversions are detailed in Methods used in standard arithmetic conversions. The way operands and subexpressions are grouped does not necessarily specify the actual order in which they are evaluated by the compiler (see Evaluation order).
Expressions can produce an lvalue, an rvalue, or no value. Expressions might cause side effects whether they produce a value or not
The precedence and associativity of the operators are summarized in Associativity and precedence of C++Builder operators. The grammar in C++Builder expressions, completely defines the precedence and associativity of the operators.
C++Builder expressions
primary-expression: literal this (C++ specific) :: identifier (C++ specific) :: operator-function-name (C++ specific) :: qualified-name (C++ specific) (expression) name literal: integer-constant character-constant floating-constant string-literal name: identifier operator-function-name (C++ specific) conversion-function-name (C++ specific) ~ class-name (C++ specific) qualified-name (C++ specific) qualified-name: (C++ specific) qualified-class-name :: name postfix-expression: primary-expression postfix-expression [ expression ] postfix-expression (<expression-list>) simple-type-name (<expression-list>) (C++ specific) postfix-expression . name postfix-expression -> name postfix-expression ++ postfix-expression -- const_cast < type-id > ( expression ) (C++ specific) dynamic_cast < type-id > ( expression ) (C++ specific) reinterpret_cast < type-id > ( expression ) (C++ specific) static_cast < type-id > ( expression ) (C++ specific) typeid ( expression ) (C++ specific) typeid ( type-name ) (C++ specific) expression-list: assignment-expression expression-list , assignment-expression unary-expression: postfix-expression ++ unary-expression - - unary-expression unary-operator cast-expression sizeof unary-expression sizeof ( type-name ) allocation-expression (C++ specific) deallocation-expression (C++ specific) unary-operator: one of & * + - ! allocation-expression: (C++ specific) <::> new <placement> new-type-name <initializer> <::> new <placement> (type-name) <initializer> placement: (C++ specific) (expression-list) new-type-name: (C++ specific) type-specifiers <new-declarator> new-declarator: (C++ specific) ptr-operator <new-declarator> new-declarator [<expression>] deallocation-expression: (C++ specific) <::> delete cast-expression <::> delete [] cast-expression cast-expression: unary-expression ( type-name ) cast-expression pm-expression: cast-expression pm-expression .* cast-expression (C++ specific) pm-expression ->* cast-expression (C++ specific) multiplicative-expression: pm-expression multiplicative-expression * pm-expression multiplicative-expression / pm-expression multiplicative-expression % pm-expression additive-expression: multiplicative-expression additive-expression + multiplicative-expression additive-expression - multiplicative-expression shift-expression: additive-expression shift-expression << additive-expression shift-expression >> additive-expression relational-expression: shift-expression relational-expression < shift-expression relational-expression > shift-expression relational-expression <= shift-expression relational-expression >= shift-expressionequality-expression: relational-expression equality expression == relational-expression equality expression != relational-expression AND-expression: equality-expression AND-expression & equality-expression exclusive-OR-expression: AND-expression exclusive-OR-expression ^ AND-expression inclusive-OR-expression: exclusive-OR-expression inclusive-OR-expression | exclusive-OR-expression logical-AND-expression: inclusive-OR-expression logical-AND-expression && inclusive-OR-expression logical-OR-expression: logical-AND-expression logical-OR-expression || logical-AND-expression conditional-expression: logical-OR-expression logical-OR-expression ? expression : conditional-expression assignment-expression: conditional-expression unary-expression assignment-operator assignment-expression assignment-operator: one of =, *=, /=, %=, +=, -= <<, =>, >=, &=, ^=, |= expression: assignment-expression expression , assignment-expression constant-expression: conditional-expression