ADVERTISEMENT
ADVERTISEMENT

How to Implement Return Parameters in Golang?

Golang | Named Return Parameters: Write a Go language program to demonstrate the example of named return parameters.
Submitted by IncludeHelp, on October 22, 2021

In the Go programming language, the named return parameters are also known as the named parameters. Golang allows giving the names to the return or result parameters of the functions in the function signature or definition.

Syntax:

func function_name(Parameter-list)(Return_type){
    // function body ...
}

Example:

// Golang program to implement the
// Named Return Arguments

package main

import "fmt"

// function having named arguments
func CalculateSumSub(x, y int) (sum int, sub int) {
	// Assign the result to the arguments
	sum = x + y
	sub = x - y

	// return statement without any value
	return
}

// Main function
func main() {
	a, b := 10, 20
	res1, res2 := CalculateSumSub(a, b)

	fmt.Println("Sum:", res1)
	fmt.Println("Sub:", res2)
}

Output:

Sum: 30
Sub: -10

Golang FAQ »

ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.