Created
May 16, 2018 01:39
-
-
Save k-kurikuri/5e4a167cf7d19352e5b741fae7cba03a to your computer and use it in GitHub Desktop.
...が可変パラメータを表すというサンプルコード
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() { | |
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