Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

arrays.go 554B

il y a 3 semaines
123456789101112131415161718192021222324252627282930313233343536
  1. package main
  2. import "fmt"
  3. func arrays() {
  4. var a [5]int
  5. fmt.Println("emp: ", a)
  6. a[4] = 100
  7. fmt.Println("set: ", a)
  8. fmt.Println("get: ", a[4])
  9. fmt.Println("len: ", len(a))
  10. b := [5]int{1, 2, 3, 4, 5}
  11. fmt.Println("dcl: ", b)
  12. b = [...]int{1, 2, 3, 4, 5}
  13. fmt.Println("dcl: ", b)
  14. b = [...]int{100, 3: 400, 500}
  15. fmt.Println("idx: ", b)
  16. var twoD [2][3]int
  17. for i := 0; i < 2; i++ {
  18. for j := 0; j < 3; j++ {
  19. twoD[i][j] = i + j
  20. }
  21. }
  22. fmt.Println("2d: ", twoD)
  23. twoD = [2][3]int{
  24. {1, 2, 3},
  25. {1, 2, 3},
  26. }
  27. fmt.Println("2d: ", twoD)
  28. }