Bird
0
0

What does the question mark (?) signify when used in a Swift variable declaration like var age: Int??

easy📝 Conceptual Q2 of 15
Swift - Optionals
What does the question mark (?) signify when used in a Swift variable declaration like var age: Int??
AThe variable is a constant and cannot change
BThe variable is automatically unwrapped
CThe variable is a string type
DThe variable is an optional and may hold a value or nil
Step-by-Step Solution
Solution:
  1. Step 1: Identify the meaning of ? in Swift

    The question mark after a type means the variable can hold a value or no value (nil).
  2. Step 2: Understand optional behavior

    This makes the variable optional, requiring safe unwrapping before use.
  3. Final Answer:

    The variable is an optional and may hold a value or nil -> Option D
  4. Quick Check:

    Question mark means optional = B [OK]
Quick Trick: ? means the variable can be nil or hold a value [OK]
Common Mistakes:
  • Confusing ? with constant declaration
  • Assuming ? means string type
  • Thinking ? auto unwraps the value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes