Learning Golang: Function declarations

Share on:

This is part 4 of my journey learning Golang.

Function declarations

Functions are reusable blocks of code. For example:

1func main () {
2    fmt.Println("Hello, World!")
3}

The func keyword declares a function. It is followed by the function’s name, a list of arguments (delimited by parenthesis) and the function block (delimited by curly braces).

main function

In Go, the main function is special. When the main function is defined in the main package, it is automatically called when the program is executed.


comments powered by Disqus