Skip to content

Latest commit

 

History

History
55 lines (37 loc) · 860 Bytes

README.md

File metadata and controls

55 lines (37 loc) · 860 Bytes

Functions

A function can take zero or more arguments.

In this example, add takes two parameters of type int.

Notice that the type comes after the variable name.

package main

import "fmt"

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

func main() {
	fmt.Println(add(42, 13))
}

When two or more consecutive named function parameters share a type, you can omit the type from all but the last.

In this example, we shortened

x int, y int

to

x, y int

Check this out:

package main

import "fmt"

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

func main() {
	fmt.Println(add(42, 13))
}

Read More: Go's Declaration Syntax

Navigate

<< Hello WOrld in Golang | List Of Content | Variables >>