Saturday, 4 May 2019

Go Language: Functions continued


When two or more consecutive parameters to a function taking same type, you can omit the type from all except the last.

func add(x, y, z int) int {
         return x + y + z
}

App.go
package main

import (
 "fmt"
)

func main() {
 result := add(10, 20, 30)

 fmt.Println("Sum of 10, 20, 30 is ", result)

}

func add(x, y, z int) int {
 return x + y + z
}

Output
Sum of 10, 20, 30 is  60



Previous                                                 Next                                                 Home

No comments:

Post a Comment