Golang Program that Uses Named Return Values and Defaults Last Updated : 17 May, 2020 Comments Improve Suggest changes Like Article Like Report 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 take an example: C // Golang Program that Uses Named // Return Values and Defaults package main import "fmt" // taking a function having named return // values as dsa and placement func courses(numbers []int) (dsa int, placement int) { // If the slice is at least two // elements set dsa and placement. // Else, leave the return values as zero. if len(numbers) >= 2 { dsa = numbers[0] placement = numbers[len(numbers)-1] } return dsa, placement } func main() { // For a zero-element // slice, these will return 0. fmt.Println("Displaying Default Values For Named Return Values") prices := []int{} fmt.Println(courses(prices)) fmt.Println() fmt.Println("Displaying Assigned Values For Named Return Values") // The dsa and placement // values are set now prices = []int{2499, 7499} fmt.Println(courses(prices)) } Example: Displaying Default Values For Named Return Values 0 0 Displaying Assigned Values For Named Return Values 2499 7499 Create Quiz Comment S shivanisinghss2110 Follow 0 Improve S shivanisinghss2110 Follow 0 Improve Article Tags : Go Language Golang-Program Explore OverviewGo Programming Language (Introduction) 7 min read How to Install Go on Windows? 3 min read How to Install Golang on MacOS? 4 min read Hello World in Golang 3 min read FundamentalsIdentifiers in Go Language 3 min read Go Keywords 2 min read Data Types in Go 7 min read Go Variables 9 min read Constants- Go Language 6 min read Go Operators 9 min read Control StatementsGo Decision Making (if, if-else, Nested-if, if-else-if) 5 min read Loops in Go Language 5 min read Switch Statement in Go 2 min read Functions & MethodsFunctions in Go Language 3 min read Variadic Functions in Go 3 min read Anonymous function in Go Language 2 min read main and init function in Golang 2 min read What is Blank Identifier(underscore) in Golang? 3 min read Defer Keyword in Golang 3 min read Methods in Golang 3 min read StructureStructures in Golang 7 min read Nested Structure in Golang 3 min read Anonymous Structure and Field in Golang 3 min read ArraysArrays in Go 7 min read How to Copy an Array into Another Array in Golang? 3 min read How to pass an Array to a Function in Golang? 2 min read SlicesSlices in Golang 14 min read Slice Composite Literal in Go 3 min read How to sort a slice of ints in Golang? 2 min read How to trim a slice of bytes in Golang? 3 min read How to split a slice of bytes in Golang? 3 min read StringsStrings in Golang 7 min read How to Trim a String in Golang? 2 min read How to Split a String in Golang? 3 min read Different ways to compare Strings in Golang 2 min read PointersPointers in Golang 8 min read Passing Pointers to a Function in Go 3 min read Pointer to a Struct in Golang 3 min read Go Pointer to Pointer (Double Pointer) 4 min read Comparing Pointers in Golang 3 min read ConcurrencyGoroutines - Concurrency in Golang 2 min read Select Statement in Go Language 4 min read Multiple Goroutines 2 min read Channel in Golang 7 min read Unidirectional Channel in Golang 2 min read Like