在 C++ 中,我在执行此操作时遇到任何运行时错误

问题描述 投票:0回答:1

创建一个大小为 5 的数组。尝试将 100 存储到数组的索引 21 中。它应该给你一个 运行时错误。请注意给出的错误的第一行。你不必处理/抓住 对于此任务的任何内容,只需记下错误即可。

我期待越界错误

c++
1个回答
0
投票
#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;
}

但是我没有收到任何运行时错误。我不明白这一点。请有人帮助我。

© www.soinside.com 2019 - 2024. All rights reserved.