Thursday, 24 June 2010

Expression

An expression is a sequence of operands and operators that reduces to a single value.

Types:

Primary Expressions
Postfix Expressions
Prefix Expressions
Unary Expressions
Binary Expressions






Primary Expressions
Consists of only one operand & no operator.
Types:
Identifiers
Literal Constants
Parenthetical Expressions
Precedence Order: 16 (highest)
Associativity: None

Postfix Expressions
Consist of one operator followed by an operand.
Types:
Function Call
Postfix Increment/Decrement
Precedence Order: 16 (highest)
Associativity: Left-Right

Postfix Increment/Decrement
The postfix increment/decrement operator increase/decrease a variable’s value by 1.
The program reads the value of the variable before the increment/decrement happens.
Result is the same as a = a + 1;
Operand must be a variable!
Postfix increments/decrements have side effects.







Prefix Expressions

Consist of one operator preceded by an operand.
Only one type – prefix increment/decrement.
Precedence Order: 15
Associativity: Right-Left


Unary Expressions

Similar to prefix expressions – consist of one operator preceded by an operand.
Unlike prefix expressions, operand may be variable or expression.
Types:
sizeof
Uninary Plus/Minus
Cast Operator
Associativity: Right-Left


No comments:

Post a Comment