Bird
0
0

What will be the output of this code? struct Product: Identifiable { let id: Int let name: String } let p = Product(id: 5, name: "Book") print(p.id)

medium📝 Predict Output Q4 of 15
iOS Swift - Lists and Data Display
What will be the output of this code? struct Product: Identifiable { let id: Int let name: String } let p = Product(id: 5, name: "Book") print(p.id)
Anil
B5
CError: Missing id property
D"Book"
Step-by-Step Solution
Solution:
  1. Step 1: Understand struct properties

    The struct has an id property of type Int and a name property.
  2. Step 2: Analyze print statement

    Printing p.id outputs the integer 5 assigned during initialization.
  3. Final Answer:

    5 -> Option B
  4. Quick Check:

    Accessing id property prints its value = D [OK]
Quick Trick: Print id property to see its value [OK]
Common Mistakes:
  • Confusing id with name property
  • Expecting error without reason
  • Assuming id is optional

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes