Lecture22 - ComputerProgrammingITAC162. Todays Agenda...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Computer Programming I TA C162 . 20/01/06 Today’s Agenda Precedence and Associativity of Operators Examples More about Input and Output Formatted Input Formatted Output Examples
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Computer Programming I TA C162 . 20/01/06 What is Precedence and Associativity? Operators have rules that are used to determine how expressions are evaluated. Precedence and associativity deal with the evaluation order within expressions Precedence rules specify the order in which operators of different precedence level are evaluated Associativity rules decides the order in which multiple occurrences of the same level operator are applied.
Background image of page 2
3 Computer Programming I TA C162 . 20/01/06 Rules of Evaluation of Expression 1. First, parenthesized sub expression from left to right are evaluated. 2. If parentheses are nested, the evaluation begins with the innermost sub expression. 3. The precedence rule is applied in determining the order of application of operators in evaluating sub-expressions. 4. The associativity rule is applied when two or more operators of the same precedence level appear in a sub expression.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Computer Programming I TA C162 . 20/01/06 Precedence of Arithmetic Operators Two priority levels of operators High priority *, /, % Low priority + - Consider the expression 1+2*3 * has higher priority than + So the value of the expression is 7
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 18

Lecture22 - ComputerProgrammingITAC162. Todays Agenda...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online