Golang Program that Uses Multiple Return Values Last Updated : 23 Aug, 2021 Comments Improve Suggest changes Like Article Like Report In Golang, we can return multiple values at a time from a single function. Multiple return values can be achieved by changing the return type of the function in the function signature. Syntax : func value( ) ( int , int ) { return 1 , 0 ; } The (int, int) in this function signature explains that the return type is two integers. Thus we have to use multiple assignments while calling this function. This feature is also used to return both results and error from a function. If you want a subset of the returned values, use the blank identifier _. Example 1: Finding max and min of two elements, using this feature : Go package main import "fmt" // declaring a function // having return type // of int, int func maxmin(a int, b int) (int, int) { if a > b { // separate multiple return // values using comma return a, b } else { return b, a } // this function returns // maximum , minimum values } func main() { // declaring two values a and b var a = 50 var b = 70 // calling the function // with multiple assignments var max, min = maxmin(a, b) // Printing the values fmt.Println("Max = ", max, "\nMin = ", min) } Output : Max = 70 Min = 50 Example 2: Finding the sum and difference of two numbers, using this feature of multiple return values. Go package main import "fmt" // declaring a function having // return type of int, int func sumDiff(a int, b int) (int, int) { return (a + b), (a - b) // this function returns sum , // difference of the two numbers } func main() { // declaring two values a and b var a = 68 var b = 100 // calling the function // with multiple assignments var sum, diff = sumDiff(a, b) // Printing the values fmt.Println("Sum = ", sum, "\nDifference = ", diff) } Output : Sum = 168 Difference = -32 Multiple Return Values and Go Formatting Tools in Go Programming Language Comment More infoAdvertise with us Next Article Golang Program that uses String Switch M ManishKhetan Follow Improve Article Tags : Go Language Golang-Program Similar Reads Golang Program that Uses Named Return Values and Defaults Golang functions have special functionality that allows them to provide the name to the return values. These named return values can be used as arguments or variables. The named return values also use the default values for the data types like 0 for int type etc. To understand this concept let's tak 1 min read Golang Program that uses func as Local Variable Function performs a specific task, section of code that defined once can be reused. Functions are used to make your code easier to understand by breaking it into small and understandable tasks.Functions are also known as method, sub-routine, or procedure. General form of a function definition in Go 3 min read Golang Program that uses String Switch With the help of switch case we can implement the functionality of as many if statements. In Golang, switch cases can work with strings, list of variables including integer values as well as floating values. Syntax: switch optstatement; optexpression{case expression1: Statement..case expression2: St 1 min read Golang program that uses func with variable argument list In Golang, a function that can be called with a variable argument list is known as a variadic function. One can pass zero or more arguments in the variadic function. If the last parameter of a function definition is prefixed by ellipsis ..., then the function can accept any number of arguments for t 2 min read Naming the Return Values of a Function in Golang A return value helps to retain the final output of the function after it performs the instructions given in its body. Functions in Golang exhibit variety in return values and rely on the programmer to decide whether to name them or not. Golang introduces a concept of "Naked Return" allowing the use 3 min read Function Returning Multiple Values in Go Language In Go language, you are allowed to return multiple values from a function, using the return statement. Or in other words, in function, a single return statement can return multiple values. The type of the return values is similar to the type of the parameter defined in the parameter list. Syntax: fu 3 min read Like