August 2021
Beginner
112 pages
1h 23m
English
| Puzzle 10 | A Simple Append |
| | package main |
| | |
| | import ( |
| | "fmt" |
| | ) |
| | |
| | func main() { |
| | a := []int{1, 2, 3} |
| | b := append(a[:1], 10) |
| | fmt.Printf("a=%v, b=%v\n", a, b) |
| | } |
Guess the Output | |
|---|---|
|
|
Try to guess what the output is before moving to the next page. |
This code will print: a=[1 10 3], b=[1 10]
You’ll need to dig a bit into how slices are implemented and how append works to understand why you seed this output.
If you look at ...
Read now
Unlock full access