Answers for "2d slice in golang"

Go
0

2d slice in golang

// Allocate the top-level slice.
slice2D := make([][]uint8, rowSize) // One row per unit of y.
// Loop over the rows, allocating the slice for each row.
for i := range slice2D {
	slice2D[i] = make([]uint8, columnSize)
}
/**
## Slice in golang:
	- Because slices are variable-length, it is possible to have 
      each inner slice be a different length.
	- There are two ways to achieve this. 
		a. One is to allocate each slice independently; 
		b. the other is to allocate a single array and point 
           the individual slices into it.
*/
Posted by: Guest on July-03-2021

Browse Popular Code Answers by Language