GOLANGTESTS Telegram 770
🧠 Задача на Go (1.22+)


package main

import "fmt"

func main() {
m = map[string]int{"a": 1, "b": 2, "c": 3}

defer fmt.Println("done")

for k, v := range m {
defer fmt.Println(k, v)
}
}


Что выведет этот код?

A.
c 3
b 2
a 1
done

B.
done
a 1
b 2
c 3

C.
done
c 3
b 2
a 1

D.
a 3
a 3
a 3
done

Почему A? — в Go 1.22 range-переменные k и v создаются на каждом шаге заново, а defer захватывает копии, не ссылки.



tgoop.com/golangtests/770
Create:
Last Update:

🧠 Задача на Go (1.22+)


package main

import "fmt"

func main() {
m = map[string]int{"a": 1, "b": 2, "c": 3}

defer fmt.Println("done")

for k, v := range m {
defer fmt.Println(k, v)
}
}


Что выведет этот код?

A.
c 3
b 2
a 1
done

B.
done
a 1
b 2
c 3

C.
done
c 3
b 2
a 1

D.
a 3
a 3
a 3
done

Почему A? — в Go 1.22 range-переменные k и v создаются на каждом шаге заново, а defer захватывает копии, не ссылки.

BY Go tests


Share with your friend now:
tgoop.com/golangtests/770

View MORE
Open in Telegram


Telegram News

Date: |

Telegram iOS app: In the “Chats” tab, click the new message icon in the right upper corner. Select “New Channel.” Telegram users themselves will be able to flag and report potentially false content. The group also hosted discussions on committing arson, Judge Hui said, including setting roadblocks on fire, hurling petrol bombs at police stations and teaching people to make such weapons. The conversation linked to arson went on for two to three months, Hui said. The best encrypted messaging apps The group’s featured image is of a Pepe frog yelling, often referred to as the “REEEEEEE” meme. Pepe the Frog was created back in 2005 by Matt Furie and has since become an internet symbol for meme culture and “degen” culture.
from us


Telegram Go tests
FROM American