gpt4 book ai didi

c++ - 数组运行时错误

转载 作者:太空宇宙 更新时间:2023-11-04 15:51:23 25 4
gpt4 key购买 nike

我不明白为什么会出现运行时错误:

the variable ia is being used without being initialized.

不过,据我所知,我已经初始化了它。

#include <iostream>
using namespace std;

int main()
{
//array dimensions
const int row_size = 2;
const int col_size = 4;

//array definition
int ia[row_size][col_size] = {{0, 1, 2, 3},{5, 6, 7, 8}};

cout << ia[2][4];

system("PAUSE");
return 0;
}

最佳答案

C++ 数组索引是从零开始的。因此,要访问第二行的第四列,您需要访问 ia[1][3]

关于c++ - 数组运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7699802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com