Bird
0
0

What will be the output of this Swift code?

medium📝 Predict Output Q5 of 15
Swift - Functions
What will be the output of this Swift code?
func displayProduct(_ x: Int, _ y: Int) {
    print(x * y)
}

displayProduct(5, 6)
A56
Bx * y
C30
DError: Missing argument labels
Step-by-Step Solution
Solution:
  1. Step 1: Understand function parameters

    Both parameters use _, so no labels are needed when calling.
  2. Step 2: Calculate output

    Calling displayProduct(5, 6) multiplies 5 by 6, printing 30.
  3. Final Answer:

    30 -> Option C
  4. Quick Check:

    Underscore omits labels, prints product [OK]
Quick Trick: Underscore omits labels; prints product of numbers [OK]
Common Mistakes:
  • Expecting argument labels in call
  • Confusing multiplication with concatenation
  • Assuming code causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes