Sobes.tech
Junior — Middle

Can you list the main data structures used in Go?

sobes.tech AI

Answer from AI

In the Go language, the main data structures include:

  • Arrays — fixed-size sequences of elements of the same type.
  • Slices — dynamic, resizable views of arrays.
  • Maps — hash tables for storing key-value pairs.
  • Structs — user-defined types that group multiple fields.
  • Channels — for passing data between goroutines.

Example of using a slice and a map:

package main
import "fmt"

func main() {
    // Slice
    nums := []int{1, 2, 3}
    nums = append(nums, 4)

    // Map
    ages := map[string]int{"Alice": 30, "Bob": 25}
    ages["Charlie"] = 35

    fmt.Println(nums)  // [1 2 3 4]
    fmt.Println(ages)  // map[Alice:30 Bob:25 Charlie:35]
}
Can you list the main data structures used in Go… - sobes.tech