the other operand Float double long double float double long double double

The other operand float double long double float

This preview shows page 31 - 38 out of 38 pages.

the other operand. Float double long double float double long double double double long double Long double long double long double float double long double This ruler can be represented in following table Note No exponentiation operator Operators are overloaded to work with more than one type of object
Image of page 31
Integer Division Integer Division Define the integer division by (a/b)*b + a%b (a/b)*b + a%b a (b a (b 0) 0) Integer division produces an integer result Truncates the result Examples 3/2 evaluates to 1 4/6 evaluates to 0 10/3 evaluates to 3
Image of page 32
Mod Mod Produces the remainder of the division Examples 5 % 2 evaluates to 1 12 % 4 evaluates to 0 4 % 5 evaluates to 4 When operands are negative the sign of result of modulus expression is compiler dependant. In Microsoft C++, the result of a modulus expression is always the same as the sign of the first operand. For instance, 5%(-2) evaluates to 1 -5%2 evaluates to -1 (-5)%(-2) evaluates to -1
Image of page 33
Unary Arithmetic Operators Unary Arithmetic Operators +35, -40, -a Mixed Mixed - - mode expression mode expression Usual arithmetic conversion for mixed-mode expression int int long float double long float double long double long double int long float double long double Long long float double long double float float float double long double int int long long float float double double long double long double long double long double long double long double long double double double double double long double
Image of page 34
Precedence and Precedence and Associativity Associativity Consider m*x + b which of the following is it equivalent to (m * x) + b m * (x + b) Operator precedence tells how to evaluate expressions Standard precedence order () Evaluate first, if nested innermost done first * / % Evaluate second. If there are several, then evaluate from left-to-right + - Evaluate third. If there are several, then evaluate from left-to-right Left associativity and Right associativity
Image of page 35
Defining and Initializing Defining and Initializing When an object is defined using the basic form, the memory allotted to it contains random information Better idea to specify its desired value at the time of definition Exception is when the next statement is an extraction for the object Remember our convention of one definition per statement! Compute average velocity of a car
Image of page 36
Home works Home works Page98, Exercises 2.10 Page99, Exercises 2.17 + 2.18 Page102, Exercises 2.33 Page102, Exercises 2.34
Image of page 37
End of Chapter 2 End of Chapter 2
Image of page 38

You've reached the end of your free preview.

Want to read all 38 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes