Golang ProgramsGolang Programs

Give name to return value of a function

We can also name the return value by defining variables, here a variable total of integer type is defined in the function declaration for the value that the function returns.
package main

import "fmt"

func main() {
	fmt.Println(add(20, 30))

func add(x int, y int) (total int) {
	total = x + y
	return total
C:\golang\example>go run test1.go