Created
March 23, 2016 18:53
-
-
Save debedb/5c73e4114b52908ca7f9 to your computer and use it in GitHub Desktop.
Go arrays and pointers
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
// See https://play.golang.org/p/qK05tDYCFR | |
package main | |
import "fmt" | |
type Make struct { | |
Name string | |
} | |
type Model struct { | |
Make Make | |
} | |
type Models []Model | |
func main() { | |
fmt.Println("Hello, playground") | |
cars := Models{Model{Make{"corolla"}}, Model{Make{"camry"}}} | |
fmt.Println(cars) | |
for _, car := range cars { | |
car.Make.Name = "Nova" | |
} | |
fmt.Println(cars) | |
for i, _ := range cars { | |
car := &cars[i] | |
car.Make.Name = "nova" | |
} | |
fmt.Println(cars) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment