Initial commit - learning the basics
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
var aa [2]string
|
||||
|
||||
aa[0] = "Hello"
|
||||
aa[1] = "World"
|
||||
fmt.Println(aa[0], aa[1])
|
||||
fmt.Println(aa)
|
||||
|
||||
primes := [6]int{2, 3, 5, 7, 11, 13}
|
||||
fmt.Println(primes)
|
||||
|
||||
var s []int = primes[1:4]
|
||||
fmt.Printf("The primes are %d and the slice is %d", primes, s)
|
||||
|
||||
// Slices are references to array sections
|
||||
// Changing elements in a slice results in changes to the array
|
||||
// So other slices referencing the same array section will also be changed
|
||||
|
||||
names := [4]string{
|
||||
"John",
|
||||
"Paul",
|
||||
"George",
|
||||
"Ringo",
|
||||
}
|
||||
fmt.Println(names)
|
||||
|
||||
a := names[0:2]
|
||||
b := names[1:3]
|
||||
fmt.Println(a, b)
|
||||
|
||||
// Now make some changes
|
||||
b[0] = "XXX"
|
||||
fmt.Println(a, b)
|
||||
fmt.Println(names)
|
||||
}
|
||||
Reference in New Issue
Block a user