Bird
0
0

What will be the output of this Swift code?

medium📝 Predict Output Q4 of 15
Swift - Basics and Runtime
What will be the output of this Swift code?
let name = "Swift"
print("Hello, \(name)!")
AError: Invalid syntax
BHello, \(name)!
CHello, Swift!
DHello, name!
Step-by-Step Solution
Solution:
  1. Step 1: Understand string interpolation in Swift

    Using \(variable) inside a string inserts the variable's value.
  2. Step 2: Apply interpolation to the code

    "Hello, \(name)!" becomes "Hello, Swift!" when printed.
  3. Final Answer:

    Hello, Swift! -> Option C
  4. Quick Check:

    String interpolation = Hello, Swift! [OK]
Quick Trick: Use \(var) to insert variable values in strings [OK]
Common Mistakes:
  • Printing the literal \(name)
  • Confusing variable name with string
  • Syntax errors in string interpolation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes