-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconcepts.go
More file actions
50 lines (42 loc) · 698 Bytes
/
concepts.go
File metadata and controls
50 lines (42 loc) · 698 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
40
41
42
43
44
45
46
47
48
49
50
package main
import "fmt"
func slice() {
s := []int{1, 2, 3}
t := s
t[0] = 99
fmt.Println(s[0], t[0])
}
func zeroValues() {
var x int
var s string
var b bool
fmt.Println(x, s, b)
}
func rangeExample() {
nums := []int{10, 20, 30}
for i, v := range nums {
fmt.Printf("index=%d value=%d\n", i, v)
}
}
func variadicSum(nums ...int) int {
total := 0
for _, num := range nums {
total += num
}
return total
}
type Rectangle struct {
Width float64
Height float64
}
func (r *Rectangle) Area() float64 {
return r.Width * r.Height
}
func main() {
zeroValues()
slice()
rangeExample()
fmt.Println(variadicSum(1, 2, 3, 4, 5))
r := Rectangle{3.0, 4.0}
fmt.Println(r.Area())
}