Skip to content

Instantly share code, notes, and snippets.

@k-kurikuri
Created May 16, 2018 01:39
Show Gist options
  • Save k-kurikuri/5e4a167cf7d19352e5b741fae7cba03a to your computer and use it in GitHub Desktop.
Save k-kurikuri/5e4a167cf7d19352e5b741fae7cba03a to your computer and use it in GitHub Desktop.
...が可変パラメータを表すというサンプルコード
package main
import "fmt"
func main() {
fmt.Println("\nExample I")
testArgs([]int{1,2,3}...)
fmt.Println("\nExample II")
testArgs(1,2,3,4,5)
fmt.Println("\nExample III")
testArgs()
fmt.Println("\nDynamic Array")
intArray := [...] int {1,2,3,4,5,6,7}
fmt.Println("Length: ",len(intArray))
fmt.Println("Capacity: ",cap(intArray))
fmt.Println(intArray)
fmt.Println("\nInterface")
interfaces := []interface{}{"A", "B", "C"}
fmt.Println(interfaces)
}
func testArgs(arg ...int) {
fmt.Println("Length of Arguments: ",len(arg))
fmt.Printf("Arguments: %+v\n",arg)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment