Go Developer (Go Arrays)

0.0(0)
Studied by 3 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/6

flashcard set

Earn XP

Description and Tags

Step by step guide to becoming a Go developer in 2023

Last updated 5:37 PM on 1/25/24
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

7 Terms

1
New cards

What are arrays?

Arrays are used to store multiple values of the same type in a single variable, instead of declaring separate variables for each value.

2
New cards

Write the two ways to declare an array with the var keyword:

var array_name = [length]datatype{values}
var array_name = [...]datatype{values}

3
New cards

Write the two ways to declare an array with := sign:

array_name := [length]datatype{values}
array_name := [...]datatype{values} // here length is inferred

4
New cards

What is the output of this snippet?:
package main
import ("fmt")

func main() {
  var arr1 = [3]int{1,2,3}
  arr2 := [5]int{4,5,6,7,8}

  fmt.Println(arr1)
  fmt.Println(arr2)
}

[1 2 3]
[4 5 6 7 8]

5
New cards

What is the output of this snippet?:
package main
import ("fmt")

func main() {
  var arr1 = [...]int{1,2,3}
  arr2 := [...]int{4,5,6,7,8}

  fmt.Println(arr1)
  fmt.Println(arr2)
}

[1 2 3]
[4 5 6 7 8]

6
New cards

Write a snippet to print the following output with inferred lengths:
[1 2 3]
[4 5 6 7 8]

package main
import ("fmt")

func main() {
var arr1 = [...]int{1,2,3}
arr2 := [...]int{4,5,6,7,8}
fmt.Println(arr1)
fmt.Println(arr2)
}

7
New cards

What is the output of this code:

package main
import ("fmt")

func main() {
  arr1 := [5]int{1:10,2:40}

  fmt.Println(arr1)
}

[0 10 40 0 0]