Complete the code to declare an array of 5 integers in C++.
int arr[[1]];The array size must be a fixed integer. Here, 5 means the array can hold 5 integers.
Complete the code to access the third element of the array named 'arr'.
int value = arr[[1]];Array indexing starts at 0, so the third element is at index 2.
Fix the error in the code to correctly initialize an array with values 1, 2, 3.
int arr[3] = { [1] };
Array initialization uses commas to separate values inside braces.
Fill both blanks to create a loop that prints all elements of an array 'arr' of size 'n'.
for (int i = [1]; i [2] n; i++) { std::cout << arr[i] << ' '; }
The loop starts at 0 and runs while i is less than n (not less or equal) to avoid out-of-bounds access.
Fill all three blanks to create a function that returns the sum of elements in an integer array.
int sumArray(int arr[], int n) {
int sum = 0;
for (int i = [1]; i [2] n; i[3]) {
sum += arr[i];
}
return sum;
}The loop starts at 0, runs while i is less than n, and increments i by 1 each time.
