Arrays and slices have a different internal structure. Especially, a slice has a header struct that contains a pointer that points to an underlying array, whereas an array is, well, just that.
The range operator cannot iterate over a pointer to a struct, but it can iterate over a pointer to an array.
To make the slice variant compile, dereference the pointer:
for k := range *p
Playground link (which also shows a more Go-ish way of initializing a pointer to a slice.)