Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        5年前关闭。
                                                                                            
                
        
我正在尝试学习C ++,当我进入数组时,在尝试运行此代码时想到了这一点:

Unhandled exception at 0x00c3151f in array.exe: 0xC0000005: Access violation writing location 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/

10-11 05:52