Hello World Program in Go
In this tutorial, we will learn how to write a Hello World program in Go language. We will go through each statement of the program.
Go Program
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
Output
Hello, World!
Working of the "Hello, World!" Program
package main
This line defines the package name. Themain
package is special because it defines a standalone executable program in Go.import "fmt"
This line imports thefmt
package, which contains functions for formatted I/O, including printing to the console.func main()
This line defines the main function, where the program execution begins. In Go, the main function is the entry point of the program.{
This opening brace marks the beginning of the main function's body.fmt.Println("Hello, World!")
This line prints the string "Hello, World!" to the console. ThePrintln
function from thefmt
package adds a new line after the text.}
This closing brace marks the end of the main function's body.