How does the C language modify the values of an array?
To change the values of an array, you can access and modify array elements using their index.
For example, given an array of type int called arr, we can use indexes to modify the values in the array.
int arr[5] = {1, 2, 3, 4, 5};
// 修改数组第一个元素的值
arr[0] = 10;
// 修改数组第二个元素的值
arr[1] = 20;
// 修改数组第三个元素的值
arr[2] = 30;
In the code above, we modify the value of the array using arr[index]. The index starts at 0, representing the position in the array.
Caution: make sure the index value is within the valid range of the array, as accessing or modifying an index outside the array’s range may cause the program to crash or exhibit undefined behavior.