Bird
0
0

What is the output of this Swift code?

medium📝 Predict Output Q4 of 15
Swift - Variables and Constants
What is the output of this Swift code?
let x = 2; let y = 3
print(x * y)
A23
B6
Cx * y
DSyntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable assignment with semicolons

    Both variables x and y are assigned correctly using semicolons to separate statements on the same line.
  2. Step 2: Calculate the multiplication

    print(x * y) outputs 2 * 3 = 6.
  3. Final Answer:

    6 -> Option B
  4. Quick Check:

    Correct output = B [OK]
Quick Trick: Semicolons separate statements; output is calculated normally [OK]
Common Mistakes:
  • Confusing semicolon usage with output
  • Thinking semicolons affect arithmetic
  • Expecting string concatenation instead of multiplication

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes