Bird
0
0

Which of the following Swift variable declarations uses type inference correctly?

easy📝 Syntax Q12 of 15
Swift - Variables and Constants
Which of the following Swift variable declarations uses type inference correctly?
Alet number = 10
Blet number: = 10
Clet number Int = 10
Dlet number : Int 10
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax for variable declaration with type inference

    Type inference allows omitting the type, so let number = 10 is correct.
  2. Step 2: Identify syntax errors in other options

    Options B, C, and D have syntax errors: missing type name, wrong order, or missing assignment operator.
  3. Final Answer:

    let number = 10 -> Option A
  4. Quick Check:

    Correct syntax with inference = let number = 10 [OK]
Quick Trick: Look for correct Swift syntax without explicit type [OK]
Common Mistakes:
  • Adding colon without type name
  • Writing type before variable name incorrectly
  • Omitting assignment operator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes