Skip to content

Instantly share code, notes, and snippets.

@bishoyAtif
Created January 20, 2024 11:51
Show Gist options
  • Save bishoyAtif/1877d8f427dd82223a530f8a0d1bf1a1 to your computer and use it in GitHub Desktop.
Save bishoyAtif/1877d8f427dd82223a530f8a0d1bf1a1 to your computer and use it in GitHub Desktop.
Passing Array VS Slice to methods
package main
import "fmt"
func main() {
myArr := [10]int{}
mySlice := []int{1, 2}
fmt.Printf("Array location in the main method = %d\n", &myArr[0])
arrayPrintStartingLocation(myArr)
fmt.Printf("-----\n")
fmt.Printf("Slice location in the main method = %d\n", &mySlice[0])
slicePrintStartingLocation(mySlice)
}
func arrayPrintStartingLocation(passedArray [10]int) {
fmt.Printf("Array location in the arrayPrintStartingLocation method = %d\n", &passedArray[0])
}
func slicePrintStartingLocation(passedSlice []int) {
fmt.Printf("Slice location in the slicePrintStartingLocation method = %d\n", &passedSlice[0])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment