This question already has an answer here:
I am new to go programming,
Assume this code, where in function fmt.Printf()
passing two different values
package main
import "fmt"
func main() {
var a int = 150
var b int = 130
var ret1, ret2 int
ret1, ret2 = max(a, b)
fmt.Printf( "Max val: %d Min val: %d
", ret1, ret2 )
}
func max(num1, num2 int) (int,int) {
if (num1 > num2) {
return num1, num2
} else {
return num2, num1
}
}
Instead of passing ret1, ret2 in fmt.Printf( "Max val: %d Min val: %d
", ret1, ret2 )
is there any way, I can directly pass max(a, b)
in fmt.Printf()
like
fmt.Printf( "Max val: %d Min val: %d
", max(a, b))
I had tried it, it is giving error
multiple-value max() in single-value context
As it seems, returning two different values not a tuple, is my concept for this returning is wrong or I am doing it wrong.
Is there any method to pass function with multiple return directly to function require variable number of values
TIA
</div>