Golang program that uses func with two arguments
Last Updated :
10 May, 2020
Functions may use certain parameters to receive values and perform the task required accordingly. The syntax for a function with two arguments is:
func function_name( [parameter_1 parameter_2] ) [return_types]
{
body of the function
}
Example 1: Without any return type
package main
import "fmt"
func add(x int , y int ) {
var sum int = x + y
fmt.Println(sum)
}
func main() {
add(10, 20)
}
|
Output:
30
Example 2: With return type
package main
import "fmt"
func add(x int , y int ) int {
var z int = x + y
return z
}
func main() {
var sum = add(10, 20)
fmt.Println(sum)
}
|
Output:
30
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...