Swift - OptionalsWhat does the question mark (?) signify when used in a Swift variable declaration like var age: Int??AThe variable is a constant and cannot changeBThe variable is automatically unwrappedCThe variable is a string typeDThe variable is an optional and may hold a value or nilCheck Answer
Step-by-Step SolutionSolution:Step 1: Identify the meaning of ? in SwiftThe question mark after a type means the variable can hold a value or no value (nil).Step 2: Understand optional behaviorThis makes the variable optional, requiring safe unwrapping before use.Final Answer:The variable is an optional and may hold a value or nil -> Option DQuick 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 declarationAssuming ? means string typeThinking ? auto unwraps the value
Master "Optionals" in Swift9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Swift Quizzes Data Types - String is a value type behavior - Quiz 12easy Data Types - Tuples for grouped values - Quiz 5medium Loops - Labeled statements for nested loops - Quiz 1easy Loops - Why Swift loops are safe by default - Quiz 2easy Loops - Labeled statements for nested loops - Quiz 3easy Operators and Expressions - Identity operators (=== and !==) - Quiz 9hard Operators and Expressions - Identity operators (=== and !==) - Quiz 3easy Operators and Expressions - Logical operators - Quiz 2easy Optionals - Force unwrapping with ! and its danger - Quiz 12easy Variables and Constants - Let for constants (immutable) - Quiz 9hard