Arrays

Reading material

Go by example: Arrays

A Tour of Go: Arrays


First exercise

// arrays1
// Make me compile!

// I AM NOT DONE
package main

import "fmt"

func main() {
	var colors [3]string

	colors[0] = "red"
	colors[1] = "green"
	colors[2] = "blue"

	fmt.Printf("First color is %s:\n", colors[])
	fmt.Printf("Last color is %s:\n", colors[])
}

Second exercise

// arrays2
// Make me compile!

// I AM NOT DONE
package main

import "fmt"

func main() {
	names := [4]string{"John", "Maria", "Carl", 10}
	fmt.Println(names)
}


If something is wrong in this page, edit this page on GitHub