nuances in go defer
tags: learning programming go
content
in go-defer, i wrote
Transclude of go-defer#defer-note
- this is not exactly true!
deferis executed after return statement, but it’s before actual return- that’s why it can modify return value
in this example:
Transclude of go-defer#defer-example
- that’s why it can modify return value
in this example:
- after
return 1,defer funcis executed, that’s why inside it prints 1 - and it modifies return value, that’s why in
mainit prints 2