&x), strings (although they’re immutable) slices, maps and channels are all passed by reference, meaning that their values can be updated inside a function(int, error)(value, error) where error != nil indicates some error has occurredfunc main() {
f := os.Stdin
if len(os.Args) > 1 {
if f, err := os.Open(os.Args[1]); err != nil {
...
}
defer f.close()
}
// At this point we can do something with the file and only if it is a file passed in the params will it be closed at function exit
}
f.close() running at function exit not block endingfunc thing() {
a := 10
defer fmt.Println(a)
a = 11
fmt.Println(a)
// Will print 11,10
}