Skip to content

Instantly share code, notes, and snippets.

@hi-manshu
Created July 12, 2018 16:35
Show Gist options
  • Save hi-manshu/fa4eabfb29c6f50d6276faadcfd5c9a8 to your computer and use it in GitHub Desktop.
Save hi-manshu/fa4eabfb29c6f50d6276faadcfd5c9a8 to your computer and use it in GitHub Desktop.
package main
//imported the fmt package
import "fmt"
//this is a function which returns a single maximum value
func maxValue(a, b int) int {
if a > b {
return a
}
return b
}
//this is the function which returns two values, one is the sum and other is the product of two number
func addAndProduct(a, b int) (int, int) {
return a + b, a * b
}
//main function gets called when the program executes
func main() {
//this is how we assign the values to the return values
addition, product := addAndProduct(20, 30)
//print the max value from 2,3
fmt.Println(maxValue(2, 3))
//prints the value of addition from addAndProduct function
fmt.Println("Addition: ", addition)
//prints the value of product from addAndProduct function
fmt.Println("Product: ", product)
}
>>go run functionExample.go
>>3
>>Addition: 50
>>Product: 600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment