How to Create and Print Multi Dimensional Slice in Golang? Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Slice is a variable-length sequence which stores elements of a similar type, you are not allowed to store different type of elements in the same slice. It is just like an array having an index value and length, but the size of the slice is resized they are not in fixed-size just like an array. Internally, slice and an array are connected with each other, a slice is a reference to an underlying array. It is allowed to store duplicate elements in the slice. The first index position in a slice is always 0 and the last one will be (length of slice – 1). Multi-dimensional slice is just like the multidimensional array, except that slice does not contain the size. Example: C // Golang program to illustrate // the multi-dimensional slice package main import "fmt" func main() { // Creating multi-dimensional slice s1 := [][]int{ {1, 2}, {3, 4}, {5, 6}, {7, 8}, } // Accessing multi-dimensional slice fmt.Println("Slice 1 : ", s1) // Creating multi-dimensional slice s2 := [][]string{ []string{"str1", "str2"}, []string{"str3", "str4"}, []string{"str5", "str6"}, } // Accessing multi-dimensional slice fmt.Println("Slice 2 : ", s2) // Printing every slice inside s2 fmt.Println("MultiDimensional Slice s2:") for i := 0; i < len(s2); i++ { fmt.Println(s2[i]) } // Printing elements in slice as matrix fmt.Println("Slice s2 Like Matrix:") // number of rows in s2 n := len(s2) // number of columns in s2 m := len(s2[0]) for i := 0; i < n; i++ { for j := 0; j < m; j++ { fmt.Print(s2[i][j] + " ") } fmt.Print("\n") } } Output: Slice 1 : [[1 2] [3 4] [5 6] [7 8]] Slice 2 : [[str1 str2] [str3 str4] [str5 str6]] MultiDimensional Slice s2: [str1 str2] [str3 str4] [str5 str6] Slice s2 Like Matrix: str1 str2 str3 str4 str5 str6 Comment More infoAdvertise with us Next Article How to repeat a slice of bytes in Golang? M Mayank Rana 1 Follow Improve Article Tags : Go Language Golang-Slices Golang-Program Similar Reads How to Get First and Last Element of Slice in Golang? Go language slice is more powerful, flexible, convenient than an array, and is a lightweight data structure. Slice is a variable-length sequence which stores elements of a similar type, you are not allowed to store different type of elements in the same slice. It is just like an array having an inde 2 min read How to find the capacity of Channel, Pointer and Slice in Golang? Go language, capacity defines the maximum number of elements that a particular can hold. Here the task is to find the capacity of Channel, Pointer, and Slice in Golang, we can use the cap() function. Syntax: func cap(l Type) int Here, the type of l is a pointer. Let us discuss this concept with the 2 min read How to repeat a slice of bytes in Golang? In Go language slice is more powerful, flexible, convenient than an array, and is a lightweight data structure. The slice is a variable-length sequence which stores elements of a similar type, you are not allowed to store different type of elements in the same slice. In the Go slice of bytes, you ar 3 min read How to pass a Slice to Function in Golang? In Go, slices are dynamically sized arrays. They are often passed to functions when you want to manipulate or process collections of data. Slices are passed by reference, meaning that any modification made to the slice inside the function will affect the original slice outside the function.Examplepa 4 min read How to Compare Equality of Struct, Slice and Map in Golang? In Golang, reflect.DeepEqual function is used to compare the equality of struct, slice, and map in Golang. It is used to check if two elements are "deeply equal" or not. Deep means that we are comparing the contents of the objects recursively. Two distinct types of values are never deeply equal. Two 3 min read How to append a slice in Golang? In Go, slices are dynamically-sized, flexible views into the elements of an array. Appending elements to a slice is a common operation that allows for the expansion of the slice as needed. The built-in append function is used to add elements to the end of a slice.In this article,we will learn How to 2 min read Like