demo

demo


# Part 1: Hello World


Here the hello world program in Go


```go

package main


import "fmt"


func main() {

fmt.Println("Hello World")

}

```


Save the following program as `helloworld.go` in the hello directory we just created.


Use `go run` command to run the Program

```bash

go run helloworld.go

```


### Short explanation of the hello world program


```go

package main //1


import "fmt" //2


func main() { //3

fmt.Println("Hello World") //4

}

```

1. Every go file must start with the `package name` statement. Packages are used to provide code compartmentalisation and reusability. Here the package name used is `main`

2. `import "fmt"` - The fmt package is imported and it will be used inside the main function to print text to the standard output.

3. `func main()` - The main is a special function. The program execution starts from the main function. The main function should always reside in the main package. The `{` and `}` indicate the start and end of the main function.

4. `fmt.Println("Hello World")` - The `Println` function of the `fmt` package is used to write text to the standard output.


Report Page