Go Program to Print Hello World

In this post, we will learn how to write a program to print “Hello, World!” using the Go programming language.

“Hello, World!” is an entry-level program used to understand the basic syntax of any programming language. Developers get a rough idea about the syntax of languages after writing the “Hello, World!” program.

This tutorial will teach you how to display any string or message on the screen.

Go Program to Print Hello World

package main

import (
	"fmt"
)

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

Output

Hello, World!

How Does This Program Work?

package main

The first line states that this code belongs to the main package.

import (
	"fmt"
)

After that, we import the fmt package. The fmt stands for the format, and this package contains basic input and output functions.

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

The execution of code starts with the main function. The fmt.Println() function is used to print the message inside the quotation mark on the screen.

Anything written under the quotation mark will be printed on the screen.

Conclusion

In this post, you learned how to write a program to print “Hello, World!” on the screen using the Go programming language.

If you have any doubts regarding the tutorial, leave your queries in the comment section.

Leave a Comment

Your email address will not be published. Required fields are marked *