@kjk1/

book pointer dereference

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.465035275347232","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"cGFja2FnZSBtYWluCgppbXBvcnQgImZtdCIKCi8vIDpzaG93IHN0YXJ0CnR5cGUgUGVyc29uIHN0cnVjdCB7CglOYW1lIHN0cmluZwp9CgpmdW5jIG1haW4oKSB7CgljIDo9IG5ldyhQZXJzb24pIC8vIHJldHVybnMgcG9pbnRlcgoJYy5OYW1lID0gIkNhdGhlcmluZSIKCWZtdC5QcmludGxuKGMuTmFtZSkgLy8gcHJpbnRzOiBDYXRoZXJpbmUKCWQgOj0gYwoJZC5OYW1lID0gIkRhbmllbCIKCWZtdC5QcmludGxuKGMuTmFtZSkgLy8gcHJpbnRzOiBEYW5pZWwKCS8vIEFkZGluZyBhbiBBc3Rlcml4IGJlZm9yZSBhIHBvaW50ZXIgZGVyZWZlcmVuY2VzIHRoZSBwb2ludGVyCglpIDo9ICpkCglpLk5hbWUgPSAiSW5lcyIKCWZtdC5QcmludGxuKGMuTmFtZSkgLy8gcHJpbnRzOiBEYW5pZWwKCWZtdC5QcmludGxuKGQuTmFtZSkgLy8gcHJpbnRzOiBEYW5pZWwKCWZtdC5QcmludGxuKGkuTmFtZSkgLy8gcHJpbnRzOiBJbmVzCgkvLyA6c2hvdyBlbmQKfQ=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package main

import "fmt"

// :show start
type Person struct {
	Name string
}

func main() {
	c := new(Person) // returns pointer
	c.Name = "Catherine"
	fmt.Println(c.Name) // prints: Catherine
	d := c
	d.Name = "Daniel"
	fmt.Println(c.Name) // prints: Daniel
	// Adding an Asterix before a pointer dereferences the pointer
	i := *d
	i.Name = "Ines"
	fmt.Println(c.Name) // prints: Daniel
	fmt.Println(d.Name) // prints: Daniel
	fmt.Println(i.Name) // prints: Ines
	// :show end
}