Bird
0
0

Which of the following is the correct syntax for explicit type annotation in Swift?

easy📝 Syntax Q12 of 15
Swift - Variables and Constants
Which of the following is the correct syntax for explicit type annotation in Swift?
Avar age: Int = 25
Bvar age = Int: 25
Cvar age Int = 25
Dvar age = 25: Int
Step-by-Step Solution
Solution:
  1. Step 1: Recall Swift syntax for explicit type annotation

    The correct syntax is to write the variable name, then a colon, then the type, then an equals sign and the value.
  2. Step 2: Check each option

    var age: Int = 25 matches this syntax exactly. The other options have misplaced colons or missing punctuation.
  3. Final Answer:

    var age: Int = 25 -> Option A
  4. Quick Check:

    Variable name : Type = value [OK]
Quick Trick: Remember: variableName: Type = value [OK]
Common Mistakes:
  • Putting colon after the value
  • Missing colon between name and type
  • Using equal sign before type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes