Created
January 20, 2024 11:51
-
-
Save bishoyAtif/1877d8f427dd82223a530f8a0d1bf1a1 to your computer and use it in GitHub Desktop.
Passing Array VS Slice to methods
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() { | |
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