Q
In C++, what happens when int a[5]; a[7] = 3; is executed?
-
A
The array automatically grows
-
B
Compilation error
-
C
std::out_of_range is thrown
-
D
Undefined behavior; there is no compile-time or runtime bounds check
Correct Answer:
D. Undefined behavior; there is no compile-time or runtime bounds check
Explanation:
Built-in arrays are not bounds-checked. std::vector::at() does check bounds and throws out_of_range.