Which of the following creates an empty array of Integers in Swift?
easy📝 Conceptual Q2 of 15
Swift - Collections
Which of the following creates an empty array of Integers in Swift?
Alet numbers = []
Blet numbers = Int[]
Clet numbers: [Int] = []
Dlet numbers = [0]
Step-by-Step Solution
Solution:
Step 1: Understand empty array creation
An empty array must have its type specified if no elements are given.
Step 2: Check each option
let numbers: [Int] = [] explicitly declares an empty array of Int type. let numbers = Int[] is invalid because Swift array type syntax is [Int], not Int[]. let numbers = [] is invalid because type cannot be inferred from empty brackets. let numbers = [0] creates an array with one element, 0.
Final Answer:
let numbers: [Int] = [] -> Option C
Quick Check:
Empty array with type annotation = let numbers: [Int] = [] [OK]
Quick Trick:Empty arrays need explicit type or initializer [OK]
Common Mistakes:
Using [] without type annotation
Confusing empty array with array containing zero
Using incorrect syntax like let numbers = []
Master "Collections" in Swift
9 interactive learning modes - each teaches the same concept differently