package main
import "fmt"
func main() {
// Step 1: Create an array with 5 numbers
numbers := [5]int{5, 8, 3, 7, 1}
// Step 2: Access the value at position 2
value := numbers[2]
// Step 3: Print the array and the accessed value
for i, v := range numbers {
fmt.Printf("[%d] -> %d\n", i, v)
}
fmt.Printf("Value at position 2 is %d\n", value)
}
numbers := [5]int{5, 8, 3, 7, 1}
Create an array with fixed size and values
Directly access the value at index 2 for fast retrieval
for i, v := range numbers {
fmt.Printf("[%d] -> %d\n", i, v)
}
Print all array elements with their positions
fmt.Printf("Value at position 2 is %d\n", value)
Show the accessed value from the array
[0] -> 5
[1] -> 8
[2] -> 3
[3] -> 7
[4] -> 1
Value at position 2 is 3