O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7

Answers to Chapter 7 Review Questions

1: How are the following expressions evaluated in C#:
  1. 5 + 10 * 2

  2. 5 * 6 / 3

  3. 12 / 4 * 6

  4. 20 % 8

  5. myIntVariable++

  6. --myIntVariable

A1:
  1. 5 + (10 * 2) = 5 + 20 = 25

  2. (5 * 6) / 3 = 30 / 3 = 10

  3. (12 / 4) * 6 = 3 * 6 = 18

  4. 20 % 8 = 4

  5. The value of myIntVariable is incremented by one. If myIntVariable++ is part of a longer expression, this increment will take place after other operations in the expression.

  6. The value of myIntVariable is decremented by one. If --myIntVariable is part of a longer expression this decrement will take place before other operations in the expression.

2: Suppose you need to add number1 and number2 together and multiply this result by number3. The first attempt:
number1 + number2 * number3

gave a wrong ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required