-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstruct.go
More file actions
39 lines (31 loc) · 742 Bytes
/
struct.go
File metadata and controls
39 lines (31 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import "fmt"
type Book struct {
id int
author string
title string
}
var book Book
func printBook(book Book) {
fmt.Println("id:", book.id)
fmt.Println("author:", book.author)
fmt.Println("title:", book.title)
}
func printBook2(book *Book) {
fmt.Println("id:", book.id)
fmt.Println("author:", book.author)
fmt.Println("title:", book.title)
}
func main() {
book1 := Book{1, "go tutorial", "jincheng9"}
book2 := Book{id:2, title:"day day up", author:"unknown"}
printBook(book1)
printBook(book2)
book.id = 10
book.author = "test"
book.title = "test"
printBook(book)
book3 := Book{1, "expert", "go"}
bookPtr := &book3
printBook2(bookPtr)
}