Bird
0
0

Which of the following Swift declarations will cause a syntax error?

easy📝 Syntax Q3 of 15
Swift - Optionals
Which of the following Swift declarations will cause a syntax error?
Avar age: Int?
Bvar isActive: Bool?
Cvar name: String?
Dvar score: ?Double
Step-by-Step Solution
Solution:
  1. Step 1: Check correct placement of ? in optional declarations

    The ? must come after the type, not before it.
  2. Step 2: Identify invalid syntax

    var score: ?Double places ? before Double, which is invalid syntax in Swift.
  3. Final Answer:

    var score: ?Double causes syntax error -> Option D
  4. Quick Check:

    Optional ? goes after type, not before [OK]
Quick Trick: Place ? after the type, never before [OK]
Common Mistakes:
  • Writing ? before the type
  • Confusing optional with forced unwrapping syntax
  • Missing type after ?

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes