LoginSignup
0
0

More than 3 years have passed since last update.

Goの変数定義の仕方

Posted at

変数定義の仕方

Bo☆Be☆Ro☆Ku
n番煎じ

sample.go
// 宣言、代入
var s string
s = "string"

// 型宣言と代入を一緒に
var s string = "string"

// 型省略
var s = "string"

// var省略
s := "string"

// 同じ型で複数宣言
var s1, s2 string
s1, s2 = "s1", "s2"
// 同じ値を代入はNG
s1, s2 = "s"

// 同じ型で複数代入
s1, s2 := "s1", "s2"

// 別々の型複数宣言
var (
  i int
  s string
)

// 別々の型複数代入
var (
  i = 1
  s = "s"
)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0