When I'm following this golang blog post about arrays and slices, I tried to pass a pointer to a slice to a function that modify the underlying len
property in the slice header:
func PtrSubtractOneFromLength(slicePtr *[]byte) {
slice := *slicePtr
*slicePtr = slice[0 : len(slice)-1]
}
And when I tried to refactor it to this from:
func PtrSubtractOneFromLength(slicePtr *[]int) {
*slicePtr = *slicePtr[0 : len(*slicePtr)-1]
}
I get this error
cannot slice slicePtr (type *[]int)
Where is the magic in the slice := *slicePtr
statement?