mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Merge pull request #657 from szaydel/master
Golang - lack of information about named return values in functions
This commit is contained in:
commit
2597370686
@ -116,6 +116,16 @@ can include line breaks.` // Same string type.
|
|||||||
learnFlowControl() // Back in the flow.
|
learnFlowControl() // Back in the flow.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// It is possible, unlike in many other languages for functions in go
|
||||||
|
// to have named return values.
|
||||||
|
// Assigning a name to the type being returned in the function declaration line
|
||||||
|
// allows us to easily return from multiple points in a function as well as to
|
||||||
|
// only use the return keyword, without anything further.
|
||||||
|
func learnNamedReturns(x, y int) (z int) {
|
||||||
|
z = x * y
|
||||||
|
return // z is implicit here, because we named it earlier.
|
||||||
|
}
|
||||||
|
|
||||||
// Go is fully garbage collected. It has pointers but no pointer arithmetic.
|
// Go is fully garbage collected. It has pointers but no pointer arithmetic.
|
||||||
// You can make a mistake with a nil pointer, but not by incrementing a pointer.
|
// You can make a mistake with a nil pointer, but not by incrementing a pointer.
|
||||||
func learnMemory() (p, q *int) {
|
func learnMemory() (p, q *int) {
|
||||||
|
Loading…
Reference in New Issue
Block a user