I am the beginner in this Golang. If you are looking for expert, I am not that guy. Anyway, I will tri to write this post as the beginner.

 

1. var and type

 

I think these "var" and  "type" are most used elements.

package main

import "fmt"

func main(){

 var i = 10;

 fmt.Printf("%d\n",i);

}

This is the sample case. "var 1 = 10;" is the part to define the variable. It is different from others. There is no type such as int, float or string. In the Golang, the fomular is like below.

var <names> <type> = <expression>

Value names can be multiple. With this statements, the same case should be written like below.

package main

import "fmt"

func main(){

 var i int = 10;

 fmt.Printf("%d\n",i);

}

In the GoLang, there is implicit statments like below. The "type" is followed from expression type. 

<names> := <expression>

Because of this, the sample case will be re-written like below

package main

import "fmt"

func main(){

 i := 10;

 fmt.Printf("%d\n",i);

}

 

'Programming Basic > GoLang' 카테고리의 다른 글

How to install GoLang in Ubuntu  (0) 2020.03.22

+ Recent posts