-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstruct.go
63 lines (50 loc) · 1.16 KB
/
struct.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import "fmt"
func main() {
title1, author1, year1 := "The Devin Comedy", "Dante Alighieri", 1320
title2, author2, year2 := "Macbeth", "William Shakespeare", 1606
fmt.Println("Book1:", title1, author1, year1)
fmt.Println("Book2:", title2, author2, year2)
type book struct {
title string
author string
year int
}
type book1 struct {
title, author string
year int
}
myBook := book{"The Devin Comedy", "Dante Alighieri", 1320}
fmt.Println(myBook)
bestBook := book{title: "Animal Farm", author: "George Orwell", year: 1945}
_ = bestBook
aBook := book{title: "Just a Random Book"}
fmt.Printf("%#v\n", aBook)
diana := struct {
firstName, lastName string
age int
}{
firstName: "Diana",
lastName: "Muller",
age: 30,
}
fmt.Printf("%#v\n", diana)
fmt.Printf("Diana's Age: %d\n", diana.age)
type Book struct {
string
float64
bool
}
b1 := Book{"1984 by George Orwell", 10.2, false}
fmt.Printf("%#v\n", b1)
fmt.Println(b1.string)
type Employee struct {
name string
salary int
bool
}
e := Employee{"John", 40000, false}
fmt.Printf("%#v\n", e)
e.bool = true
fmt.Printf("%#v\n", e)
}