[go] 배열 값 변경하기
To change the value of an element in an array, you can simply assign a new value to the desired index in the array. Here’s an example:
package main
import "fmt"
func main() {
arr := [3]int{1, 2, 3}
fmt.Println("Original array:", arr)
arr[1] = 5
fmt.Println("Modified array:", arr)
}
In this example, the value at index 1 in the array is changed from 2 to 5. When running this program, you’ll see the output:
Original array: [1 2 3]
Modified array: [1 5 3]
By reassigning a new value to a specific index in the array, you can effectively change the value of that element.