Help us understand the problem. What is going on with this article?

Goのスライスについて

スライスとは

goでは配列の他に配列の一部を切り出したスライスがあるらしい

配列とは違って宣言の時に[]の中が空白

スライスの扱い方

初期化

//初期値はnil
var slice []int

//長さと容量も指定できる
slice = make([]int,3,10)
//                 ↑ ↑
//            長さ 容量

配列とスライスの関係

スライスは配列の一部を切り出したもので開始終了を指定すると切り出せる
{配列名}[開始位置:終了位置]

//配列
var a = [3]int{0,1,2}

//スライス
a[1:2]
//→[1]

配列を|0|1|2|とした時に
スライスは(一番左が0)
開始位置:左から数えたときの区切り線の位置
終了位置:左から数えたときの区切り線の位置
なので
a[1:2]
左から数えたときの1番目と2番目の区切り線の間を取ってくるので1がスライスとして取得される

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away