開発環境
- macOS Catalina - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Go (プログラミング言語)
Go Systems Programming: Master Linux and Unix system level programming with Go (Mihalis Tsoukalos(著)、Packt Publishing)のChapter 2(Writing Programs in Go)、Exercises 8.の解答を求めてみる。
コード
package main
import "fmt"
func p(a [5]int, s []int) {
fmt.Printf("%T %[1]v %v %v\n", s, len(s), cap(s))
fmt.Printf("%T %[1]v %v %v\n", a, len(a), cap(a))
}
func main() {
a := [5]int{1, 2, 3, 4, 5}
s := a[:]
p(a, s)
s[1] = 10
p(a, s)
s = append(s, 11)
p(a, s)
}
入出力結果(Zsh、PowerShell、Terminal)
% go run main.go
[]int [1 2 3 4 5] 5 5
[5]int [1 2 3 4 5] 5 5
[]int [1 10 3 4 5] 5 5
[5]int [1 10 3 4 5] 5 5
[]int [1 10 3 4 5 11] 6 10
[5]int [1 10 3 4 5] 5 5
%
0 コメント:
コメントを投稿