Declare Variables with Initializers in Golang

Create new folder named src. In src folder, create new file named main.go as below:

package main

import (
	"fmt"
)

func main() {

	fmt.Println("Demo 1")
	Demo1()

	fmt.Println("Demo 2")
	Demo2()

	fmt.Println("Demo 3")
	Demo3()

}

func Demo1() {
	var age = 20
	var fullName = "abc"
	var status = true
	var price = 4.5
	var key = 'B'
	fmt.Println("age:", age)
	fmt.Println("full name:", fullName)
	fmt.Println("status:", status)
	fmt.Println("price:", price)
	fmt.Printf("key: %c and position in ASCII: %d\n", key, key)
}

func Demo2() {
	var (
		age      = 20
		fullName = "def"
		status   = false
		price    = 4.5
		key      = 'C'
	)
	fmt.Println("age:", age)
	fmt.Println("full name:", fullName)
	fmt.Println("status:", status)
	fmt.Println("price:", price)
	fmt.Printf("key: %c and position in ASCII: %d\n", key, key)
}

func Demo3() {
	var a1, a2, a3 int = 20, -5, 7
	fmt.Println("a1:", a1)
	fmt.Println("a2:", a2)
	fmt.Println("a3:", a3)
}




Open Terminal windows in Visual Studio Code and run command line: go run main.go

Demo 1
age: 20
full name: abc
status: true
price: 4.5
key: B and position in ASCII: 66

Demo 2
age: 20
full name: def
status: false
price: 4.5
key: C and position in ASCII: 67

Demo 3
a1: 20
a2: -5
a3: 7