25% off

Use code FUNCMAIN at checkout for 25% off all premium courses.

Get started →

Functions in Go

May 9, 2021
Elliot Forbes

Elliot Forbes

Course Instructor

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