func main() {
go fmt.Println("hello from goroutine")
}What happens when this program runs?
- aIt always prints "hello from goroutine" before main exits
- bIt blocks forever waiting for the goroutine to finish
- cmain may return before the goroutine runs, so the print may never happen✓
- dThe compiler rejects
goon a call whose result is not used
Explanation:
main does not wait for other goroutines. When main returns, the process exits immediately, so a goroutine started just before that can easily never get scheduled. There is no implicit join, and go fmt.Println(...) compiles fine even though the return value is discarded.