DEV Community

Cover image for Hello World in Go
vasanthkumar
vasanthkumar

Posted on • Updated on

Hello World in Go

13 Sep,2023 10:42 PM

  • Installed Go to my Macbook with brew install go

  • To check whether Go is installed or not use go in the terminal and if it returns some commands that can be combined with go

Hello, World

  • wrote the first Hello World program in Go
package main
import 'fmt'
func main() {
     fmt.Println("Hello, World")
}
Enter fullscreen mode Exit fullscreen mode
  • compiled the helloworld.go with go build helloworld.go which created an executable.

  • executed with ./helloworld

  • We can compile and execute with a single command go run helloworld.go which didn't create any executable file.

Variables

variables in go can be declared in the following ways

var a int
var b bool
a = 15 
b = true


var (
x int
y bool
)
x=100
y=false

m:=100
n:="New N"

var i,j int
i=1
j=2
Enter fullscreen mode Exit fullscreen mode

GitHub commit link

Resources

Top comments (0)