Video:

Functions in Go

May 9, 2021

Course Instructor: Elliot Forbes

Hey Gophers! My name is Elliot and I'm the creator of TutorialEdge and I've been working with Go systems for roughly 5 years now.

Code

package main

import "fmt"

func HelloWorld(name string, age, height int) {
	fmt.Println("Hello", name)
	fmt.Println("Age", age)
	fmt.Println("Height:", height)
}

func AddTotal(a, b int) (int, int) {
	return a + b, a - b
}

func main() {
	fmt.Println("Functions in Go")
	HelloWorld("Elliot", 27, 200)
	total, negativeTotal := AddTotal(2, 3)
	fmt.Println(total)
	fmt.Println(negativeTotal)
}

Output

$ go run main.go
Functions in Go
Hello Elliot
Age 27
Height: 200
5
-1