Hello World in Golang

First add the package main in your program:

package main

Every Go file must start with a package name statement. Packages provide code encapsulation and reuse. The name of the package here is main.

After adding main package import “fmt” p…


This content originally appeared on DEV Community and was authored by Neeraj Kumar

  • First add the package main in your program:
package main

Every Go file must start with a package name statement. Packages provide code encapsulation and reuse. The name of the package here is main.

  • After adding main package import “fmt” package in your program:
import(
"fmt"
)

Import the fmt package, which will be used to print text to the standard output in the main function.

  • Now write the code in the main function to print hello world in Go language:
func main() {  
    fmt.Println("Hello World") 
}

func main():

The main function is a special function that is the entry point of a Go program. The main function must be included in the main package. { and } denote the start and end of the main function.

fmt.Println(“Hello World”):

The Println function in the fmt package is used to print text to standard output.


This content originally appeared on DEV Community and was authored by Neeraj Kumar


Print Share Comment Cite Upload Translate Updates
APA

Neeraj Kumar | Sciencx (2023-02-25T18:05:11+00:00) Hello World in Golang. Retrieved from https://www.scien.cx/2023/02/25/hello-world-in-golang/

MLA
" » Hello World in Golang." Neeraj Kumar | Sciencx - Saturday February 25, 2023, https://www.scien.cx/2023/02/25/hello-world-in-golang/
HARVARD
Neeraj Kumar | Sciencx Saturday February 25, 2023 » Hello World in Golang., viewed ,<https://www.scien.cx/2023/02/25/hello-world-in-golang/>
VANCOUVER
Neeraj Kumar | Sciencx - » Hello World in Golang. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/02/25/hello-world-in-golang/
CHICAGO
" » Hello World in Golang." Neeraj Kumar | Sciencx - Accessed . https://www.scien.cx/2023/02/25/hello-world-in-golang/
IEEE
" » Hello World in Golang." Neeraj Kumar | Sciencx [Online]. Available: https://www.scien.cx/2023/02/25/hello-world-in-golang/. [Accessed: ]
rf:citation
» Hello World in Golang | Neeraj Kumar | Sciencx | https://www.scien.cx/2023/02/25/hello-world-in-golang/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.