Home > Articles > Programming > General Programming/Other Languages

  • Print
  • + Share This
This chapter is from the book

Workshop

The workshop contains quiz questions and exercises to help you solidify your understanding of the material covered. Try to answer all questions before looking at the answers that follow.

Quiz

  1. What is the difference between postfix and prefix unary operators?
  2. In the following code, what is the value of the constant c?

    let a = 11
    let b = 5
    let c = a % b
  3. In the following code, what is the value of the variable a?

    var a = 5
    let b = 6
    a *= b
  4. In the following code, what is the value of the constant b?

    let a = 5
    let b = -a
  5. What is the difference between two dots with a left angle bracket (..<) and three dots (...) in a range operation?

Answers

  1. The postfix increment does not increase the value of its operand until after it has been evaluated. The prefix decrement increases the value of its operand before it has been evaluated.
  2. The value of c after the remainder operator is 1.
  3. The value of a after the compound assignment is 30.
  4. The value of b after the unary minus operation is -5.
  5. The two dot with left angle bracket range (..<) is a half-closed range because the upper limit is noninclusive. The three dot range (...) is a closed range because the upper limit is inclusive.
  • + Share This
  • 🔖 Save To Your Account