Bird
0
0

What will be printed by this Swift code?

medium📝 Predict Output Q5 of 15
Swift - Variables and Constants
What will be printed by this Swift code?
let text = "Swift"
let length = text.count
print(type(of: length))
AString
BDouble
CCharacter
DInt
Step-by-Step Solution
Solution:
  1. Step 1: Understand type of text.count

    text.count returns the number of characters as an Int.
  2. Step 2: Print the type of length variable

    type(of: length) prints Int because length is Int.
  3. Final Answer:

    Int -> Option D
  4. Quick Check:

    String count returns Int [OK]
Quick Trick: String.count returns Int type [OK]
Common Mistakes:
  • Assuming count returns String or Character
  • Confusing count with length property
  • Expecting Double type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes