Complete the code to declare an array of 5 integers.
int arr[[1]];The number inside the square brackets specifies the size of the array. Here, 5 means the array can hold 5 integers.
Complete the code to access the third element of the array.
int value = arr[[1]];Array indexing in C++ starts at 0, so the third element is at index 2.
Fix the error in the code to prevent out-of-bounds access.
for (int i = 0; i < [1]; i++) { cout << arr[i] << " "; }
The array size is 5, so the loop should run while i is less than 5 to avoid accessing invalid elements.
Fill both blanks to create a dictionary that maps array indices to their values for elements greater than 10.
std::map<int, int> result = {
{ [1], arr[[2]] }
};We use the index 2 for both the key and to access the value in the array.
Fill all three blanks to create a loop that sums all elements in the array.
int sum = 0; for (int [1] = 0; [2] < [3]; [1]++) { sum += arr[[1]]; }
The variable i is used as the loop counter, and the loop runs while i is less than 5, the array size.