Wednesday, 1 May 2019

Go Language : := : Short Assignment statement


var i int = 1

By using short assignment statement ':=', you can define above variable 'i' like below.

i := 1

App.go
package main

import (
 "fmt"
)

func main() {
 var i int = 1
 j := 2

 fmt.Println("i : ", i, ", j : ", j)

}

Output
i :  1 , j :  2

Note
a.   Short assignment statement is available within a function, you can’t use it outside a function.




Previous                                                 Next                                                 Home

No comments:

Post a Comment