Learn about Golang program to print Hello World in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
Golang program to print Hello World
//Golang program to print "Hello World".
package main
import "fmt"
func main() {
//Declare a string type variable
var var1 string
//Assign a string to the variable
var1 = "Hello World"
fmt.Println(var1)
}
In the above program, we imported the fmt package that includes the files of package fmt then we can use a function related to the fmt package. Now, we come to the main() function. The main() function is the entry point for the program. Here, we declared a string var1. Then we initialized the variable var1 by “Hello World” message. After that, we printed the message using Println() function on the console screen.