add: unfinished code. people are having problems

This commit is contained in:
Inanc Gumus
2018-11-13 17:43:25 +03:00
parent 67b20e5755
commit 490223331c
103 changed files with 4218 additions and 3 deletions

View File

@@ -0,0 +1,24 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import "fmt"
func main() {
a := [3]int{5, 4, 7}
// this assignment will create a new array value
// and then it will be stored in the b variable
b := a
fmt.Println("a =>", a)
fmt.Println("b =>", b)
// they're equal, they're clones
fmt.Println("a==b?", a == b)
}

View File

@@ -0,0 +1,27 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import "fmt"
func main() {
a := [3]int{5, 4, 7}
b := a
// this will only change the 'a' array
a[0] = 10
fmt.Println("a =>", a)
fmt.Println("b =>", b)
// this will only change the 'b' array
b[1] = 20
fmt.Println("a =>", a)
fmt.Println("b =>", b)
}

View File

@@ -0,0 +1,23 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import "fmt"
func main() {
a := [3]int{5, 4, 7}
b := [3]int{6, 9, 3}
b = a
fmt.Println("b =>", b)
b[0] = 100
fmt.Println("a =>", a)
fmt.Println("b =>", b)
}

View File

@@ -0,0 +1,23 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
func main() {
// you can't assign the array 'a' to the array 'b'
// a's type is [2]int whereas b's type is [3]int
// when two values are not comparable,
// then they're not assignable either
// uncomment and observe the error
// a := [2]int{5, 4}
// b := [3]int{6, 9, 3}
// b = a
}

View File

@@ -0,0 +1,31 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import "fmt"
func main() {
a := [3]int{10, 4, 7}
// like the assignment passing an array to a function
// creates a copy of the array
fmt.Println("a (before) =>", a)
incr(a)
fmt.Println("a (after) =>", a)
}
// inside the function
// the passed array 'a' is a new copy (a clone)
// it's not the original one
func incr(a [3]int) {
// this only changes the copy of the passed array
a[1]++
// this prints the copied array not the original one
fmt.Println("a (inside) =>", a)
}