Bird
0
0

What will be the output of this Swift code?

medium📝 Predict Output Q5 of 15
iOS Swift - Swift Language Essentials
What will be the output of this Swift code?
var scores: [String: Int] = ["Alice": 90, "Bob": 85]
scores["Bob"] = 95
print(scores["Bob"]!)
A90
B95
C85
Dnil
Step-by-Step Solution
Solution:
  1. Step 1: Understand dictionary update syntax

    Assigning scores["Bob"] = 95 updates Bob's score to 95.
  2. Step 2: Print updated value

    scores["Bob"]! unwraps and prints 95.
  3. Final Answer:

    95 -> Option B
  4. Quick Check:

    Dictionary value updated = 95 [OK]
Quick Trick: Updating dictionary key changes its value [OK]
Common Mistakes:
  • Expecting old value
  • Forgetting to unwrap optional
  • Assuming nil for existing key

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes