Skip to content

Instantly share code, notes, and snippets.

@manjeettahkur
Created January 11, 2023 08:34
Show Gist options
  • Save manjeettahkur/20cd1779af3c06423df51771a7be8754 to your computer and use it in GitHub Desktop.
Save manjeettahkur/20cd1779af3c06423df51771a7be8754 to your computer and use it in GitHub Desktop.
In go language everything is pass by value even slice. but in slice case slice header pass by value so both headers point to the same back array
package main
import "fmt"
func main() {
a := []byte{'A', 'M', 'N', 'J', 'E', 'E', 'T'}
b := s(a)
b[0], b[1] = b[1], b[0]
fmt.Println(string(a))
}
func s(ints []byte) []byte {
return ints
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment