Un cours pour se lancer dans la programmation avec le langage Go (golang).
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

main.go 1.6 KiB

1 år sedan
1 år sedan
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Copyright (C) 2011-2023 Patrick H. E. Foubet - E2L Ivry
  2. Ecole du Logiciel Libre : https://e2li.org/
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or any
  6. later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>
  13. *******************************************************************/
  14. package main
  15. import "fmt"
  16. func main() {
  17. i := 10
  18. fmt.Println(&i)
  19. n := &i
  20. fmt.Printf("%T\n", n)
  21. fmt.Println(n)
  22. fmt.Println(i)
  23. *n = 15
  24. fmt.Println(i)
  25. j := 5
  26. n = &j
  27. *n = 6
  28. fmt.Println(i)
  29. a := 5
  30. fmt.Println(a) // value is 5
  31. pointer(&a)
  32. fmt.Println(a) // value is 10
  33. a = 5
  34. fmt.Println(a) // value is 5
  35. value(a)
  36. fmt.Println(a) // value is still 5
  37. ar := []int{1, 2, 3, 4}
  38. fmt.Println(ar)
  39. arrval(ar)
  40. fmt.Println(ar)
  41. arrpointer(&ar)
  42. fmt.Println(ar)
  43. m := make(map[int]int)
  44. m[1] = 1
  45. m[2] = 2
  46. m[3] = 3
  47. fmt.Println(m)
  48. mapped(m)
  49. fmt.Println(m)
  50. m2 := map[int]int{1: 1}
  51. mapped(m2)
  52. fmt.Println(m2)
  53. }
  54. func pointer(x *int) {
  55. *x = 10
  56. }
  57. func value(x int) {
  58. x = 10
  59. }
  60. func arrval(a []int) {
  61. a = append(a, 5)
  62. }
  63. func arrpointer(a *[]int) {
  64. *a = append(*a, 5)
  65. }
  66. func mapped(m map[int]int) {
  67. m[4] = 4
  68. }