Multiple Return Values
// Importing the "fmt" package, which provides functions for formatted I/O.
import "fmt"
// Function vals returns two integers (3 and 7).
func vals() (int, int) {
return 3, 7
}
// The main function, which serves as the entry point for the program.
func main() {
// Calling the vals function and receiving two return values (a and b).
a, b := vals()
// Printing the value of variable 'a'.
fmt.Println(a)
// Printing the value of variable 'b'.
fmt.Println(b)
// Calling the vals function again, but using the blank identifier "_" to discard the first return value.
// Only the second return value is assigned to variable 'c'.
_, c := vals()
// Printing the value of variable 'c'.
fmt.Println(c)
}Output
Last updated