Question 1Easy
What is the output?
let d = ["a": 1]
print(d["z"] ?? 0)- nil
- Crash
- 1
- 0
Answer: D. 0
Explanation
A missing dictionary key returns nil, so ?? 0 gives 0.
Step-by-step solution
- d["z"] is nil.
- ?? default.
- 0.
Why the other options are wrong
- A. The default is applied.
- B. Missing keys return nil, no crash.
- C. Key z does not exist.