-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray.go
26 lines (22 loc) · 1.12 KB
/
array.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
package concepts
import "fmt"
// Arrays can be considered a list of elements with a defined size.
// It is not possible to change the size of an array later.
//
// To declare an array in Golang, you can use the following syntaxes:
// - var VAR_NAME [SIZE]TYPE{DEFAULT_VALUES}
// - VAR_NAME := [SIZE]TYPE{DEFAULT_VALUES}
// where:
// - VAR_NAME: the name that you're gonna use for the variable.
// - SIZE: how many elements that array will store.
// - TYPE: any of default types in Go or structs that you've created.
// - DEFAULT_VALUES: this is optional but it is used when you want to create an array with default values on it.
func Arrays() {
var words [2]string // declaring an array called words with 2 elements.
words[0] = "Hello" // assign the word "Hello" to the first element into the array
words[1] = "World" // assign the word "World" to the second element into the array
fmt.Println(words[0], words[1]) // Prints the first and the second element of the array.
fmt.Println(words) // Prints the whole array
primes := [6]int{2, 3, 5, 7, 11, 13} // declaring an array for the 6 prime numbers.
fmt.Println(primes)
}