# Slice pass as value or pointer?

**URL:** <https://forum.golangbridge.org/t/slice-pass-as-value-or-pointer/2866>\
**Category:** Getting Help\
**Created:** [June 29, 2016, 3:01am UTC](https://forum.golangbridge.org/t/slice-pass-as-value-or-pointer/2866 "2016-06-29T03:01:19Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![calmh](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/calmh/32/2896_2.png) [@calmh](https://forum.golangbridge.org/u/calmh)\
**Post date:** [June 29, 2016, 6:50am UTC](https://forum.golangbridge.org/t/slice-pass-as-value-or-pointer/2866/3 "2016-06-29T06:50:09Z")

</div>

Indeed. So to answer the question in the topic title, it’s idiomatic to have functions like `slice = doSomethingWithSlice(slice)` and less so to see `doSomethingWithSlice(&slice)`. An exception is when you declare methods on a slice type ([1](https://play.golang.org/p/0sGZjTG4c0)) as those will by necessity have pointer-to-slice receivers if they intend to modify the slice;

```go
type fibSlice []int

func (sp *fibSlice) append() {
	s := *sp
	l := len(s)

	switch l {
	case 0:
		*sp = append(s, 0)
	case 1:
		*sp = append(s, 1)
	default:
		*sp = append(s, s[l-1]+s[l-2])
	}
}

```

I avoided some of the incessant “starring” by the `s := *sp` but it still gets annoying rather quickly. It’s usually neater to just declare a struct type containing the slice if I’m going to do to much of this.

---

_[View the full topic](https://forum.golangbridge.org/t/slice-pass-as-value-or-pointer/2866)._
