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?

More than 3 years have passed since last update.

【Golang】配列

Posted at

#【Golang】配列
Golangの基礎学習〜Webアプリケーション作成までの学習を終えたので、復習を兼ねてまとめていく。 基礎〜応用まで。

package main
//配列
//サイズを変更できない。拡張性がない
//後から追加する場合は、スライスを使う

//関数では値渡しされるので、コピーが作成されて引数に取られる

import "fmt"


func main() {
	//2つの配列を作る宣言
	//[2]int が型になるため、サイズを変更できない
	var a [2]int
	fmt.Println(a)
	//>>[0, 0]

	//宣言
	b := [3]int{1,2,3}
	fmt.Println(b)
	//>>[1 2 3]

	//宣言
	var arr[2] string = [2]string {"A", "B"}
	fmt.Println(arr[0], arr[1]) 
	//>>A, B
	fmt.Println(arr)
	//>>[A B]


	//宣言 要素数省略ver
	//要素の数を自動でカウントしてくれる
	arr2 := [...] string{"A", "B"}
	fmt.Println(arr2[0], arr2[1]) 
	//>>A, B
	fmt.Println(arr)
	//>>[A B]



	//0に100,1に200を代入
	a[0] = 100
	a[1] = 200
	//aを表示
	fmt.Println(a)
	//>>[100, 200]


	//配列に追加できない
	/*
	    //初期で値を入れる
		var b [2]int = [2]int{100, 200}
		//追加
		b = append(b, 300)
		fmt.Println(b)
	*/
	


	//その他の宣言

    


}

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?