Saturday, August 22, 2009

Expressions

Expressions
An expression is a sequence of operands and operators that reduces to a single value
An operator is a language-specific syntactical token that requires an action to be taken.
An operand receives an operator’s action.

Precedence rule used to determine the order of execution between different operators in an expression. The higher the number, the earlier the execution.
Associativity rule used to determine the order of execution in which the operators with the same precedence level.

Assignment Expression
Assignment Expression evaluates the operand on the right side of the operator (=) and places its value in the variable on the left.

Postfix Increment/Decrement
The value of the postfix increments (decrements) expressions is determined before the variable is increase (decrease).

Example

int a = 7;

printf("%d\n", a)
printf("%d\n", a++)
printf("%d\n", a)

Output:
7
7
8

Prefix Increment/Decrement
The value of the prefix increments (decrements) expressions is increase then the value is determined.

Example

int a = 7;

printf("%d\n", a);
printf("%d\n", a++);
printf("%d\n", a);

Output:

7
8
8

No comments: