Bird
0
0

What will be printed by this Swift code?

medium📝 Predict Output Q13 of 15
iOS Swift - Swift Language Essentials
What will be printed by this Swift code?
let multiply = { (a: Int, b: Int) -> Int in
  return a * b
}
print(multiply(3, 4))
A34
B7
C12
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand closure parameters and return

    The closure takes two Ints and returns their product.
  2. Step 2: Calculate multiply(3, 4)

    3 * 4 equals 12, so print outputs 12.
  3. Final Answer:

    12 -> Option C
  4. Quick Check:

    3 times 4 = 12 [OK]
Quick Trick: Closures return calculated values like functions [OK]
Common Mistakes:
  • Adding instead of multiplying
  • Concatenating numbers as strings
  • Syntax errors in closure call

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes