Bird
0
0

Which of the following is the correct way to declare a variable named score with initial value 10 in Swift?

easy📝 Syntax Q12 of 15
iOS Swift - Swift Language Essentials
Which of the following is the correct way to declare a variable named score with initial value 10 in Swift?
Alet score = 10
Bvar score = 10
Cscore var = 10
Dvariable score = 10
Step-by-Step Solution
Solution:
  1. Step 1: Identify variable declaration syntax

    In Swift, var is used to declare variables that can change, and the syntax is var name = value.
  2. Step 2: Check each option

    var score = 10 uses correct syntax. let score = 10 declares a constant, not a variable. score var = 10 and variable score = 10 are invalid syntax.
  3. Final Answer:

    var score = 10 -> Option B
  4. Quick Check:

    Variable declaration = var name = value [OK]
Quick Trick: Use var for variables, let for constants [OK]
Common Mistakes:
  • Using let instead of var for variables
  • Incorrect keyword order
  • Using non-existent keywords like variable

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes