Bird
0
0

Which of the following is the correct syntax to declare an array of integers in Swift?

easy📝 Syntax Q3 of 15
iOS Swift - Swift Language Essentials
Which of the following is the correct syntax to declare an array of integers in Swift?
Avar numbers = <1, 2, 3, 4>
Bvar numbers = {1, 2, 3, 4}
Cvar numbers = (1, 2, 3, 4)
Dvar numbers = [1, 2, 3, 4]
Step-by-Step Solution
Solution:
  1. Step 1: Recall array declaration syntax

    Arrays use square brackets [] with comma-separated values.
  2. Step 2: Compare options

    Only var numbers = [1, 2, 3, 4] uses square brackets correctly.
  3. Final Answer:

    var numbers = [1, 2, 3, 4] -> Option D
  4. Quick Check:

    Arrays use square brackets = [1, 2, 3] [OK]
Quick Trick: Arrays use square brackets [] in Swift [OK]
Common Mistakes:
  • Using curly braces for arrays
  • Using parentheses which are tuples
  • Using angle brackets which are invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes