0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Go言語入門】-構造体編-

Posted at

はじめに

今回は簡単ですが構造体についてまとめておこうと思います。

struct

type Test struct {
	name string
	age  int
}

func main() {
	v := Test{name: "Taro", age: 18}
	fmt.Println(v)
}

// 出力結果
{Taro 18}

個別にアクセス

fmt.Println(v.name)

// 出力結果
Taro

値の書き換え

v.age = 20
fmt.Println(v.age)

// 出力結果
20

型の順番通りなら明示的に記述しなくてもよい

type Test struct {
	name string
	age  int
}

func main() {
	v := Test{"Taro", 18}
	fmt.Println(v)
}

// 出力結果
{Taro 18}
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?