Last active
May 23, 2016 17:49
-
-
Save cc2011/c93cbdeb7160c3ef96eeb69de6cd23cc to your computer and use it in GitHub Desktop.
Func Golang
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
func hypot(x, y float64) float64 { | |
return math.Sqrt(x*x + y*y) | |
} | |
fmt.Println(hypot(3, 4)) // "5" | |
x and y are parameters in the declaration, 3 and 4 are arguments of the call, and the function returns a float64 value. | |
Arguments are passed by value, so the function receives a copy of each argument; | |
modifica- tions to the copy do not affect the caller. However, if the argument contains some kind of ref- erence, | |
like a pointer, slice, map, function, or channel, then the caller may be affected by any modifications the function | |
makes to variables indirectly referred to by the argument. | |
You may occasionally encounter a function declaration without a body, | |
indicating that the function is implemented in a language other than Go. | |
Such a declaration defines the function signature.package math | |
func Sin(x float64) float64 // implemented in assembly language |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment