1234567891011121314151617181920212223242526272829 |
- // Functions:
- // A function can take zero or more arguments
- package examples
- import "fmt"
- // Default add function values
- const (
- X = 5
- Y = 7
- )
- // This function takes two parameters of type int
- // (and returns an int) notice that the type comes
- // after the variable name.
- //
- // This could also be written:
- // func add(x, y int) int
- // if parameters are the same type
- func add(x int, y int) int {
- return x + y
- }
- func Functions() int {
- ans := add(X, Y)
- fmt.Printf("%d + %d => %d\n", X, Y, ans)
- return ans
- }
|