March 2019
Beginner to intermediate
324 pages
7h 17m
English
Here is how you write a function in Go:
func main(){//do something}
The main function is almost always the first function that gets executed in your Go program. The main function needs to live inside the main package, since main is the entry point package for your Go program.
Here is what a function with arguments would look like:
func add(a int, b int){//a+b}
Since the a and b arguments from the preceding code are of the same type, we can also do this:
func add(a,b int){//a+b}
Now, let's say we want to return a value from our function. Here is what this would look like:
func add(a,b int)int{return a+b}
Go also allows multiple returns, so you can do this:
func addSubtract(a,b int)(int,int){return a+b,a-b}
In Go, there ...
Read now
Unlock full access