Bird
0
0

Which of the following Swift code snippets correctly declares a constant integer named count with an explicit type annotation and value 5?

easy📝 Syntax Q3 of 15
Swift - Variables and Constants
Which of the following Swift code snippets correctly declares a constant integer named count with an explicit type annotation and value 5?
Alet count = 5
Blet count: Int = 5
Cvar count = 5
Dlet count = "5"
Step-by-Step Solution
Solution:
  1. Step 1: Check constant declaration syntax

    let count = 5 uses type inference, but explicit type annotation requires let count: Int = 5.
  2. Step 2: Validate type and value

    let count: Int = 5 explicitly declares count as an integer constant with value 5, which is correct.
  3. Final Answer:

    let count: Int = 5 -> Option B
  4. Quick Check:

    Explicit type constant = let count: Int = 5 [OK]
Quick Trick: Use let with type annotation for explicit constant types [OK]
Common Mistakes:
  • Using var instead of let
  • Assigning string instead of integer
  • Omitting type when explicit type is required

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes