In the following C++ code snippet, there's a runtime error caused by accessing an array element beyond its boundaries. Your task is to modify the code to prevent this runtime error and assign the value 42 to the index 2 of the array element.
Errors
Array bound error
Report a typo
Sample Input 1:
Sample Output 1:
42Write a program in C++
#include <iostream>
int main() {
int arr[5];
arr[10] = 42;
std::cout << arr[2];
return 0;
}
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.