Created
January 11, 2023 08:34
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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