创建一个大小为 5 的数组。尝试将 100 存储到数组的索引 21 中。它应该给你一个 运行时错误。请注意给出的错误的第一行。你不必处理/抓住 对于此任务的任何内容,只需记下错误即可。
我期待越界错误
#include <iostream>
int main() {
const int size = 5;
int arr[size];
// Attempt to store 100 at index 21 (which is out of bounds)
arr[21] = 100;
// The following line will not be executed due to the error above
std::cout << "This line will not be printed." << std::endl;
return 0;
}
但是我没有收到任何运行时错误。我不明白这一点。请有人帮助我。