Created
January 27, 2015 09:54
-
-
Save giwa/98ce201764bd677bcb69 to your computer and use it in GitHub Desktop.
Go by Examples: Functions ref: http://qiita.com/giwa@github/items/ee64dac57509dbdd7d01
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" | |
// 2つのintを取りその合計を返す関数です。 | |
func plus(a int, b int) int { | |
// Goは明示的なreturnが必要です。 | |
// 例えば、最後の値を自動的に返すことはありません。 | |
return a + b | |
} | |
func main() { | |
// 関数を呼ぶのは予測通り、name(args)で呼ぶことができます。 | |
res := plus(1, 2) | |
fmt.Println("1+2 =", res) | |
} | |
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
$ go run functions.go | |
1+2 = 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment