Bird
0
0

Which of the following is the correct way to declare a variable that holds a function taking two Ints and returning an Int?

easy📝 Syntax Q12 of 15
Swift - Functions
Which of the following is the correct way to declare a variable that holds a function taking two Ints and returning an Int?
Avar operation: (Int, Int) Int
Bvar operation: Int -> Int -> Int
Cvar operation: (Int Int) -> Int
Dvar operation: (Int, Int) -> Int
Step-by-Step Solution
Solution:
  1. Step 1: Recall Swift function type syntax

    Function types are written as (ParameterTypes) -> ReturnType, with parameters separated by commas.
  2. Step 2: Check each option

    var operation: (Int, Int) -> Int correctly uses (Int, Int) -> Int. Others have syntax errors or missing arrows.
  3. Final Answer:

    var operation: (Int, Int) -> Int -> Option D
  4. Quick Check:

    Correct function type syntax = var operation: (Int, Int) -> Int [OK]
Quick Trick: Use (Type1, Type2) -> ReturnType for function types [OK]
Common Mistakes:
  • Omitting commas between parameter types
  • Missing arrow '->' in function type
  • Incorrect parameter grouping

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes