-
Notifications
You must be signed in to change notification settings - Fork 2
/
func_return.go
33 lines (27 loc) · 873 Bytes
/
func_return.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// returning multiple values from a function using a return statement.
// we can define return values name as well but by default Golang automatically detect it.
package main
import "fmt"
// assigining multiple values
// this (int, int, int) part shows that function will return 3 int values
func f(a,b,c int) (int, int, int) {
return a * b * c, a + b + c, a - b - c
}
// defines return value by names
func r(l1,l2 int) (val1, val2 int) { //(val1 int, val2 int)
val1 = l1*2
val2 = l2*5
return // val1, val2
}
func main(){
x, y, z := f(25,10,30)
fmt.Println("Value of multiply ",x)
fmt.Println("Value of addition ",y)
fmt.Println("Value of subtraction ",z)
t1, t2 := r(30,25)
fmt.Println("Value of t1(val1) ", t1)
fmt.Println("Value of t2(val2) ", t2)
// blank identifier (_) underscore
_, ok := r(t1,t2)
fmt.Println(ok)
}