Length 14
var x [9]int32
This is an example of how to create an fixed array. You can access it use normal indexing operation x[8]
for example. You can iterate any array or slice using for-range
statement, for example:
for index, value := range x { // value == x[index]
}
for index := range x {
}
for _, value := range x {
}
Length 13
var x []int32
This is a longer example of slice
, slice is a struct that stores current length, capacity and pointer to an array. to get the capacity you can use cap(x)
, to get the current length of the slice, you can use len(x)
function. To add an element to the last element you can use x = append(x,data)
function, if capacity equal to the current length, it will copied to another array, and the slice points to that new array.
Length 12