Computed sooner left to right associativity except

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: -to right associativity (except unary minus) (compute left-to-right for operators of same precedence) Find a complete chart on the book's inside cover... 10 Precedence and Associativity (arithmetic operators) Examples: X =17 - 2 * 8 ? Y = 17 - 2 - 8? Ans: X=17-(2*8) , X=1 Ans: Y = (17-2)-8, Y=7 Z = 10 + 9 * ((8 + 7) % 6) + 5 * 4 % 3 *2 + 1 ? Not sure? Confused? then use parentheses in your code! (write code for forgetful humans, not perfect machines) 11 Two Very Strange Operators: pre-fix, post-fix notation Increment, decrement operators: ++ , - Instead of statement you can use either Instead of statement you can use either num = 10; ans1 = ++num; First, incr. num to 11, then assign num to ans1. num = num + 1; num++; or ++num; num = num - 1; num--; or --num; Do you see how C++ got its name? **BUT BE VERY CAREFUL!** (see...
View Full Document

Ask a homework question - tutors are online