Un cours pour se lancer dans la programmation avec le langage Go (golang).
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

pirms 1 gada
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package main
  2. import "fmt"
  3. func main() {
  4. i := 10
  5. fmt.Println(&i)
  6. n := &i
  7. fmt.Printf("%T\n", n)
  8. fmt.Println(n)
  9. fmt.Println(i)
  10. *n = 15
  11. fmt.Println(i)
  12. j := 5
  13. n = &j
  14. *n = 6
  15. fmt.Println(i)
  16. a := 5
  17. fmt.Println(a) // value is 5
  18. pointer(&a)
  19. fmt.Println(a) // value is 10
  20. a = 5
  21. fmt.Println(a) // value is 5
  22. value(a)
  23. fmt.Println(a) // value is still 5
  24. ar := []int{1, 2, 3, 4}
  25. fmt.Println(ar)
  26. arrval(ar)
  27. fmt.Println(ar)
  28. arrpointer(&ar)
  29. fmt.Println(ar)
  30. m := make(map[int]int)
  31. m[1] = 1
  32. m[2] = 2
  33. m[3] = 3
  34. fmt.Println(m)
  35. mapped(m)
  36. fmt.Println(m)
  37. m2 := map[int]int{1: 1}
  38. mapped(m2)
  39. fmt.Println(m2)
  40. }
  41. func pointer(x *int) {
  42. *x = 10
  43. }
  44. func value(x int) {
  45. x = 10
  46. }
  47. func arrval(a []int) {
  48. a = append(a, 5)
  49. }
  50. func arrpointer(a *[]int) {
  51. *a = append(*a, 5)
  52. }
  53. func mapped(m map[int]int) {
  54. m[4] = 4
  55. }