-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.go
More file actions
45 lines (34 loc) · 849 Bytes
/
array.go
File metadata and controls
45 lines (34 loc) · 849 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
package main
import "fmt"
func main() {
// create array (empty array with the string type and length 3)
var names [3]string
// assign value to array
// if the value overflow the length, it will cause a compile-time error
names[0] = "Muhammad"
names[1] = "Luthfi"
names[2] = "Akbar"
fmt.Println(names[0])
fmt.Println(names[1])
fmt.Println(names[2])
// other way to create and assign value to array
var values = [3]int{
90,
95,
80,
}
fmt.Println(values)
fmt.Println(values[0])
fmt.Println(values[1])
fmt.Println(values[2])
// built-in function len() to get the length of array
fmt.Println(len(names))
fmt.Println(len(values))
// change value in array
names[0] = "Skha"
names[1] = "Dhiya"
names[2] = "Nisrina"
fmt.Println(names)
var lagi [10]string // array of string with length 10
fmt.Println(len(lagi))
}