Sobes.tech
Junior — Senior

What text will appear in the program output

livecode

Task condition

The example considers a Calculator structure that stores two integer properties and provides a computed property sum — the sum of these fields. Then an instance of the structure is created, a closure is declared that outputs the result of the calculation, and then the value of one of the fields is changed and the closure is called. It is necessary to determine what will be printed to the console.

struct Calculator {
    var a: Int
    var b: Int
    
    var sum: Int {
        return a + b
    }
}

var calculator = Calculator(a: 3, b: 5)

let closure = {
    print("The result is \(calculator.sum)")
}

calculator.b = 20
closure()