Golang Hello World Program

In this post, we will learn how to write hello world program in Go language.

In this post, we will learn how to write hello world program in Go language.

Hello, World! is the first program any coder writes to know the basic syntax of any new programming language.

Similarly, we will be writing our first Go Program which is Hello World Program.

So, without any delay, let’s begin the tutorial.

Golang Hello World Program
Table Of Contents 👊

Golang Hello World Program

package main 
import "fmt"

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

Output

Hello, World!

How Does This Program Work ?

package main

Every Go Program starts with package declaration.

import "fmt"

Then, we are importing the fmt(format) package into the program. It is the standard library which contains input and output functions.

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

Every function in Golang starts with func. Then, we print Hello, World! Using the Println() function.

Note: If we don’t use import “fmt”, then the Println() function will not work.

Some of the used terms in this program are as follows:- 

package main - packages are a collection of Go source files that reside in the same directory. The line package main specifies that this file belongs to the main package. 

Every Executable Go Application must contain the main function.

fmt - fmt stands for Format package. This package is all about formatting input and output.

fmt.Println() - The fmt.Println() function in Go language is used to display output.

Conclusion

I hope after reading this post, you clearly understood how to write a hello world program in the Go language.

If you still have any doubt regarding this topic, let us know in the comment Section.

Sloth Coders is a Learning Platform for Coders, Programmers and Developers to learn from the basics to advance of Coding of different langauges(python, Java, Javascript and many more).

Post a Comment