
CS 110 Notes โ Basics II 1
Copyright C. Tanner 2009
โข More on Assignment operators
o Variable = expression;
o Evaluate the expression and then store the result as the value of variable
o Compound operators
๎ += -= /= *= %=
๎ Variable compound operator expression;
๎ a += 5 ร a = a+5;
๎ a*= 5 ร a = a * 5;
๎ a *= 5 + c; ร a = a * (5+c);
๎
o Page 111 #20 Rewrite the assignment statement using a compound
operator
๎ a). x = 2 * x;
๎ b). x = x + y -2;
๎ c). sum=sum + num;
๎ do d,e for non-collected homework
โข Increment/Decrement Operators
o a = a+1;
o a = a-1;
o common, often used operation
o built in machine instructions to cover these inc, dec
o a++; ร a = a+1;
o a--; ร a = a-1;
o syntax allows ++a or a++, --a or aโ
o can use it within an expression
๎ a = b-- + c++ - d;
๎ a = --b + ++c โd;
๎ these two are *not* equivalent
๎ never ++ or -- except in a stand alone statement
โข Math Library
o Collection of methods for all elementary math functions
o Such as, pow, sqrt, floor, ceil, abs, sin, cos etc
o To use qualify the method with Math.
o . โ qualifying operator (member access operator)