Bird
0
0

What is the output of this Swift code?

medium📝 Predict Output Q5 of 15
Swift - Data Types
What is the output of this Swift code?
let response = (status: 404, message: "Not Found")
print(response.1)
A404
BError: Cannot access tuple by index
CNot Found
Dstatus
Step-by-Step Solution
Solution:
  1. Step 1: Understand tuple element indexing

    Tuple elements are zero-indexed: response.0 is 404, response.1 is "Not Found".
  2. Step 2: Check print statement

    print(response.1) prints the second element, which is "Not Found".
  3. Final Answer:

    Not Found -> Option C
  4. Quick Check:

    Tuple index 1 = second element [OK]
Quick Trick: Tuple index starts at 0, so .1 is second value [OK]
Common Mistakes:
  • Confusing index 1 with first element
  • Expecting error on index access
  • Mixing named and indexed access

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes