Wednesday 1 May 2019

Go language: Initialize multiple variables in one line


If variables are of same data type, you can initialize them in one line like below.

var i, j, k int = 1, 2, 3
  
App.go
package main

import (
 "fmt"
)

func main() {
 var i, j, k int = 1, 2, 3

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

}

Output
i :  1 , j :  2 , k :  3

Previous                                                 Next                                                 Home

No comments:

Post a Comment