Array bound error

Report a typo

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.

Sample Input 1:

Sample Output 1:

42
Write 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