Golang Hello World Program

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

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).

You may like these posts

  • Hello coders, in this post we will know how to count number of digits in an integer using Go Programming language. We will be using for loop to count the num…
  • Hello coders, in this post we will learn how to calculate compound interest using Go Programming language. Compound Interest is the interest calculated based …
  • 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 …
  • Hello coders, in this post we will learn how to add two numbers using Go Programming language. We will be using different methods to add two numbers in Go language.&…
  • Hello coders, in this post we will learn how to calculate cube of a number using Go Programming language. A Cube Number is a number multiplied by itself 3 times. …
  • Hello coders, in this post we are going to solve how to calculate electricity bill using Go Programming language. So, without further delay, let's begin this …

Post a Comment