Arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// :collection Essential Go | |
package main | |
import "fmt" | |
func main() { | |
// :show start | |
a := [2]int{4, 5} // array of 2 ints | |
// access element of array | |
fmt.Printf("a[1]: %d\n", a[1]) | |
// set element of array | |
a[1] = 3 | |
// get size of array | |
fmt.Printf("size of array a: %d\n", len(a)) | |
// when using [...] size will be deduced from { ... } | |
a2 := [...]int{4, 8, -1} // array of 3 integers | |
fmt.Printf("size of array a2: %d\n", len(a2)) | |
// :show end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment