Bird
0
0

What is the output of this Swift code?

medium📝 Predict Output Q13 of 15
Swift - Variables and Constants
What is the output of this Swift code?
let x = 3; let y = 4
print(x + y)
ASyntax error
B34
C7
DRuntime error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze semicolon usage

    The semicolon separates two statements on the same line, which is valid in Swift.
  2. Step 2: Calculate the print output

    x is 3 and y is 4, so x + y equals 7, which is printed.
  3. Final Answer:

    7 -> Option C
  4. Quick Check:

    3 + 4 = 7 [OK]
Quick Trick: Semicolons separate statements; addition works normally [OK]
Common Mistakes:
  • Thinking semicolon causes syntax error
  • Confusing concatenation with addition
  • Expecting runtime error due to semicolon

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes