Display 2.3 Precedence of Operators(1 of 4) Display 2.3 Precedence of Operators Highest precedence Scope resolution operator (done first) Dot operator Member selection Array indexing Function call Postfix increment operator(placed after the variable) Postfix decrement operator(placed after the variable) + Prefix increment operator (placed before the variable) ! Prefix decrement operator(placed before the variable) Not +★ Unary minus Unary plus Dereference & Address of new Create (allocate memory) delete Destroy (deallocate) delete[] Destroy array (deallocate) sizeof Size of object () Type cast Copyright 2006 Pearson Addison-Wesley.All rights reserved. 2-6
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 2-6 Display 2.3 Precedence of Operators (1 of 4)
Display 2.3 Precedence of Operators(2 of 4) Multiply Divide % Remainder (modulo) Lower precedence Addition (done later) Subtraction << Insertion operator(console output) > Extraction operator(console input) Copyright 2006 Pearson Addison-Wesley.All rights reserved. 2-7
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 2-7 Display 2.3 Precedence of Operators (2 of 4)
Display 2.3 Precedence of Operators(3 of 4) Display 2.3 Precedence of Operators All operators in part 2 are of lower precedence than those in part 1. < Less than 7 Greater than <= Less than or equal to >= Greater than or equal to Equal = Not equal & And Or Copyright 2006 Pearson Addison-Wesley.All rights reserved. 2-8
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 2-8 Display 2.3 Precedence of Operators (3 of 4)
Display 2.3 Precedence of Operators(4 of 4) = Assignment += Add and assign Subtract and assign * Multiply and assign Divide and assign % Modulo and assign Lowest precedence (done last) ?: Conditional operator throw Throw an exception Comma operator Copyright006 Pearson Addison-Wesley.All rights reserved. 2-9
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 2-9 Display 2.3 Precedence of Operators (4 of 4)
Precedence Examples Arithmetic before logical ◆x+1>2lx+1<-3 means: ◆(仪+1)>2‖(仪+1)<-3 Short-circuit evaluation ◆(X>=0)&&(y>1) ◆Be careful with increment operators! ◆(X>1)&&(y++) Integers as boolean values ◆All non-zero values→true ◆Zero value→false Copyright 2006 Pearson Addison-Wesley.All rights reserved. 2-10
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 2-10 Precedence Examples ¨ Arithmetic before logical ¨ x + 1 > 2 || x + 1 < -3 means: ¨ (x + 1) > 2 || (x + 1) < -3 ¨ Short-circuit evaluation ¨ (x >= 0) && (y > 1) ¨ Be careful with increment operators! ¨ (x > 1) && (y++) ¨ Integers as boolean values ¨ All non-zero values true ¨ Zero value false