Bird
0
0

Which of the following correctly declares a mutable array of strings in Swift?

easy📝 Syntax Q3 of 15
Swift - Collections
Which of the following correctly declares a mutable array of strings in Swift?
Aconst names = ["John", "Jane"]
Blet names: [String] = ["John", "Jane"]
Cvar names: [String] = ["John", "Jane"]
Dstatic var names = ["John", "Jane"]
Step-by-Step Solution
Solution:
  1. Step 1: Identify mutability keyword

    var allows mutation; let does not.
  2. Step 2: Syntax correctness

    var names: [String] = ["John", "Jane"] uses var and correct type annotation.
  3. Final Answer:

    var names: [String] = ["John", "Jane"] -> Option C
  4. Quick Check:

    var for mutable arrays [OK]
Quick Trick: var declares mutable arrays; let is immutable [OK]
Common Mistakes:
  • Using let for mutable arrays
  • Using const which is invalid in Swift

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes