Bird
0
0

What will be printed after executing this Swift REPL code?

medium📝 Predict Output Q5 of 15
Swift - Basics and Runtime
What will be printed after executing this Swift REPL code?
var total = 3
total *= 4
print(total)
A34
B7
C12
DError
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the code

    Variable total is initialized to 3.
  2. Step 2: Apply the operation

    total *= 4 multiplies total by 4, so total becomes 12.
  3. Step 3: Print the result

    print(total) outputs 12.
  4. Final Answer:

    12 -> Option C
  5. Quick Check:

    3 multiplied by 4 equals 12 [OK]
Quick Trick: *= multiplies and assigns value [OK]
Common Mistakes:
  • Adding instead of multiplying
  • Confusing *= with += operator
  • Expecting an error due to variable mutation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes