// Arrays Slices and Maps

an array in Go is a fixed-length data type that contains a contiguous block of elements of the same type.

Screenshot 2025-12-17 at 21.56.23.png

Declaring an array initializing specific elements:

// declare and initialize only the index 1, 2 with specific values
array := [5]int{1:10, 2:20}

[0][10][20][0][0]

Accessing array pointer elements:

array := [5]*int{0: new(int), 1: new(int)}

// assign values to index 0

*array[0] = 10
*array[1] = 20

[addr][addr][nil][nil][nil]

Assigning one array to another of the same type

// to assign an array to another array both of the arrays should
// have the same type

var arr1 [5]string

	arr2 := [5]string{"Red", "Green", "Blue", "Yellow", "Pink"}

	arr1 = arr2

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

	arr2[0] = "Gray"

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

Multidimensional arrays

var array [4][2]int

	array = [4][2]int{{10, 11}, {12, 13}, {14, 15}, {16, 17}}

	for _, row := range array {
		fmt.Println(row)
	}

Passing arrays between functions