Dereference a pointer to slice

I have the following code snippet:

package main

type test struct {
	arr *[]int
	val int
}

func main() {
	a := test{arr: &[]int{1, 2, 3, 4, 5}, val: 21}
	*(a.arr)[2] = 656
}


and I am getting the following error:

./4.go:13:10: invalid operation: a.arr[2] (type *[]int does not support indexing)

I am not able to understand, how to de-reference the slice pointer to modify the value.

https://play.golang.org/p/p1OA8arxM2P

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.