Bird
0
0

Which of the following expressions correctly uses the logical NOT operator in Swift?

easy📝 Conceptual Q1 of 15
Swift - Data Types
Which of the following expressions correctly uses the logical NOT operator in Swift?
Alet result = not true
Blet result = !true
Clet result = true!
Dlet result = !!true
Step-by-Step Solution
Solution:
  1. Step 1: Understand the logical NOT operator syntax in Swift

    In Swift, the NOT operator is represented by a single exclamation mark (!) placed before a Boolean value.
  2. Step 2: Evaluate each option for correct syntax

    let result = !true uses !true which is correct. let result = not true uses 'not' which is invalid in Swift. let result = true! places ! after true which is incorrect. let result = !!true uses double !! which is not valid syntax.
  3. Final Answer:

    let result = !true -> Option B
  4. Quick Check:

    Logical NOT operator = !true [OK]
Quick Trick: Use ! before a Boolean to invert it in Swift [OK]
Common Mistakes:
  • Using 'not' instead of !
  • Placing ! after the value
  • Using double !!

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes