c++ - 未处理的表达式数组 C++

标签 c++ arrays

<分区>

我正在尝试学习 C++,当我学习数组时,它在尝试运行这段代码时想到了这个:

array.exe 中 0x00c3151f 处的未处理异常:0xC0000005:访问冲突写入位置 0x00390018

这是我的代码:

#include <iostream>

using namespace std;

int main()
{
    int x;
    int y;
    int array[8][8]; //Declares an array like a chessboard

    for ( x = 0; x < 8; x++ ) {
        for ( y = 0; y < 8; x++ )
            array[x][y] = x * y; // Set each element to a value
    }
    cout<<"Array Indices:\n";
    for ( x = 0; x < 8; x++ ) {
        for ( y = 0; y < 8; x++ )
            cout<<"["<<x<<"]["<<y<<"]="<< array[x][y] <<" ";
        cout<<"\n";
    }
    cin.get();
}

最佳答案

你需要增加 y 而不是 x :

for ( y = 0; y < 8; x++ )
                    ^ This should be y

(在两个循环中)。

关于c++ - 未处理的表达式数组 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25963816/

相关文章:

c++ - 如何修改指针指向的数组

在 C 中检查结构数组是否为 'empty'

c++ - 我的基地在哪里创建?

C++ 如何使用 const 将接口(interface)传递给类方法

c++ - 如何通过 C++ 宏调用编译时错误?

java - try catch 数组吗?

arrays - 计算数组数组中的项目?

c++ - 尽管明确声明了返回类型,但对 lambda 的调用仍不明确

c++ - 尝试编写备份程序 (C++) 时,类型 ‘int(const char*)’ 和 ‘const char [11]’ 到二进制 ‘operator<<’ 的无效操作数

c - 十六进制和字符数组打印有什么区别?