C Expressions

Evaluation of Expressions

Expressions are evaluated using an assignment statement of the form
Variable = expression;

Variable is any valid C variable name. When the statement is encountered, the expression is evaluated first and then replaces the previous value of the variable on the left hand side.
All variables used in the expression must be assigned values before evaluation is attempted.
	Example of evaluation statements are 
			x = a * b – c ;
			y = b / c * a; 
			z = a – b / c + d; 


Precedence in Arithmetic Operators

An arithmetic expression without parenthesis will be evaluated from left to right using the rules of precedence of operators. There are two distinct priority levels of arithmetic operators in C.

High priority ===>   * / % 
Low priority  ===>    + - 


Rules for evaluation of expression

First parenthesized sub expression left to right are evaluated. If parenthesis are nested, the evaluation begins with the innermost sub expression.
The precedence rule is applied in determining the order of application of operators in evaluating sub expressions. The associability rule is applied when two or more operators of the same precedence level appear in the sub expression.
Arithmetic expressions are evaluated from left to right using the rules of precedence. When Parenthesis are used, the expressions within parenthesis assume highest priority.

Make Comments..!!


Oops!! No posts from user.

Download Android App