21 Operator Precedence.pptx - Topic 21 Operators and Operator Precedence 1 Prefix and Postfix Operators The operator or \u2013 can be used in two positions

21 Operator Precedence.pptx - Topic 21 Operators and...

This preview shows page 1 - 11 out of 11 pages.

Topic 21 Operators and Operator Precedence 1
Image of page 1
Prefix and Postfix Operators The operator ++ or – can be used in two positions: prefix and postfix. Examples – prefix position: x = ++a; y = --b; Examples – postfix position: x = a++; y = b--; 2
Image of page 2
Prefix OperatorsAssume following initial valuesabxy511??Statementsabxyx = ++a;6116? 3
Image of page 3
Postfix OperatorsAssume following Initial valuesabxy511??Statementsabxyx = a++;6115? 4
Image of page 4
Postfix and Prefix Operators Examples Example: a = 4; cout << "a is " << a << endl; cout << "a is " << a++ << endl; cout << "a is " << ++a << endl; Statements a Output a = 4; 4 a is 4 a is 4 a is 6 cout << "a is " << a << endl; 4 cout << "a is " << a++ << endl; 5 cout << "a is " << ++a << endl; 6 5
Image of page 5
Operator Precedence Examples Example: Assume a is 3, b is 4, c is 5. -- a * (3 + b) / 2 – c++ * b
Image of page 6
Image of page 7
Image of page 8
Image of page 9
Image of page 10
Image of page 11

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture