Skip to content

Commit

Permalink
Update comments in array section
Browse files Browse the repository at this point in the history
  • Loading branch information
sMARCHz committed May 2, 2022
1 parent 1d2bb5e commit d148022
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions arrays/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ func main() {
arr[2] = "three"
fmt.Println(arr)

// compact declaration
// Compact initialization
arr2 := [3]string{"one", "two", "three"}
fmt.Println(arr2)

// Array is a fixed-length sequence so, each index allocates the same amount of memory (i.e. each index of int array allocates 8 bytes)
// Array is a fixed-length sequence so, each elements allocate the same amount of memory (i.e. array of type int allocates 8 bytes per element)
// !! Unable to do pointer arithmetic
arr3 := [2]int{1, 2}
fmt.Println(arr3, &arr3[0], &arr3[1])

// declare with dynamic length
// Initialize with dynamic length
arr4 := [...]bool{true, true, false, true}
fmt.Println(arr4)

// Print each index's value
// Access each elements via iteration
// For-each
for k, v := range arr2 {
fmt.Printf("Index[%v] = %v\n", k, v)
Expand Down

0 comments on commit d148022

Please sign in to comment.