Test Your Knowledge: Quiz

Question 4-1. What is the difference between the = and == operators?

Question 4-2. Suppose I have four different variables, a, b, c, and d. What’s the shortest way to assign them all the value 36?

Question 4-3. What’s the difference between dividing two ints and dividing two doubles?

Question 4-4. What is the purpose of the % operator?

Question 4-5. What is the output of these operations?

  • 4 * 8

  • (4 + 8) / (4 – 2)

  • 4 + 8 / 4 – 2

Question 4-6. Let myInt = 25 to start. What is the value of myInt at each stage of the following code?

myInt += 5;
myInt -= 15;
myInt *= 4;
myInt /= 3;

Question 4-7. Describe the difference between the prefix and postfix operators.

Question 4-8. Let x = 25 and y = 5. What do these expressions evaluate to?

(x >= y)
(x >= y * 5)
(x == y)
(x = y)

Question 4-9. Let x = 25 and y = 5. What do these expressions evaluate to?

(x >= y) && (y <= x)
!(x > y)
!(x < y) && (x > y)
((x > y) || !(x < y)) && (x > y)
((x > y) && ((y < x) || (x > y))) && (x == y)

Question 4-10. Arrange these operators in order of precedence:

%
!=
?:
&&
++

Get Learning C# 3.0 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.