Multiple functions with defer statements!

Report a typo

Emma has just finished learning about defer statements! She has created a Go program that has both deferred functions and deferred fmt.Println() statements:

package main

import "fmt"

func foo() {
    fmt.Println("4️⃣")
    defer fmt.Println("5️⃣")
}

func bar() {
    defer fmt.Println("2️⃣")
    fmt.Println("3️⃣")
}

func main() {
    defer fmt.Println("1️⃣")
    defer bar()
    foo()
}

Emma is challenging her friends to guess the correct order in which they'll be printed!

Please list the output of the fmt.Println() statements below in the correct order they will be printed.

Put the items in the correct order
4️⃣
2️⃣
1️⃣
5️⃣
3️⃣
___

Create a free account to access the full topic