Sobes.tech
Junior — Senior

What will be the output of program №25

livecode

Task condition

Question: What is the output of the following Swift program?

func a() -> () -> Int {
    var counter = 0
    let closure: () -> Int = {
        counter += 10
        return counter
    }
    return closure
}

let first = a()
let second = a()
print(first() + first() + second())

Determine what number will be printed on the console after executing the code.