Bird
0
0

What will this Swift code print?

medium📝 Predict Output Q5 of 15
Swift - Optionals
What will this Swift code print?
let message: String? = "Hello"
print(message!)
Anil
BOptional("Hello")
CHello
DRuntime crash
Step-by-Step Solution
Solution:
  1. Step 1: Check the optional value

    The optional message contains the string "Hello".
  2. Step 2: Force unwrap and print

    Force unwrapping extracts the string "Hello" and prints it directly.
  3. Final Answer:

    Hello -> Option C
  4. Quick Check:

    Force unwrap non-nil optional prints value [OK]
Quick Trick: Force unwrap prints the wrapped value if not nil [OK]
Common Mistakes:
  • Expecting Optional(...) output
  • Thinking it prints nil
  • Assuming force unwrap causes crash always

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes