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

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 result. Fix the problem.

3:The following expression is correct but unclear for the reader of the code. Make it more clear.
num1 + num2 / num3 * num4 – num5 * num6 / num7
4:Write an if statement that checks whether a number (call it myNumber) of type int is even or odd. Only if myNumber is even should it write “The number is even” onscreen.
5:What is the type of the following expression if weight is of type short?
-weight
6:Improve the clarity of the following ...

Get C# Primer Plus now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.