Created
February 3, 2015 04:35
-
-
Save suzuken/1b5403a6bca80a297caf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func a(){ | |
i := 0 | |
// 引数iはdeferred functionが評価される際に評価される | |
defer fmt.Println(i) | |
i++ | |
return | |
} | |
func b(){ | |
// deferred functionはLIFO | |
for i := 0; i < 4; i++ { | |
defer fmt.Print(i) | |
} | |
} | |
func c() (i int) { | |
// deferは戻り値に影響を与える | |
defer func() { i++ }() | |
return 1 | |
} | |
func main(){ | |
// fmt.Println(c()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment