Complete the code to access the element at index 2 in the array.
int arr[] = {10, 20, 30, 40, 50};
int value = arr[[1]];
std::cout << value << std::endl;The index 2 accesses the third element in the array, which is 30.
Complete the code to update the element at index 1 to 100.
int arr[] = {5, 15, 25, 35};
arr[[1]] = 100;
std::cout << arr[1] << std::endl;Index 1 is the second element, which we update to 100.
Fix the error in the code to correctly update the last element of the array.
int arr[] = {7, 14, 21, 28};
arr[[1]] = 35;
std::cout << arr[3] << std::endl;The last element is at index 3, so we must use arr[3] to update it.
Fill both blanks to print the updated array elements after changing index 0 and index 2.
int arr[] = {1, 2, 3, 4};
arr[[1]] = 10;
arr[[2]] = 30;
for(int i = 0; i < 4; i++) {
std::cout << arr[i] << " ";
}
std::cout << std::endl;Index 0 is updated to 10 and index 2 to 30, so output is 10 2 30 4.
Fill all three blanks to update elements and print the sum of updated elements at index 1, 2, and 3.
int arr[] = {2, 4, 6, 8};
arr[[1]] = 20;
arr[[2]] = 30;
arr[[3]] = 40;
int sum = arr[1] + arr[2] + arr[3];
std::cout << sum << std::endl;We update indexes 1, 2, and 3 to 20, 30, and 40 respectively. Sum is 20 + 30 + 40 = 90.
