+ 3
C++ Question
So I have this code that I expected to output a bunch of zeros, but instead output a huge random number. I'm still getting my grip on the language here, so could anyone explain what's happening here? Here's the code: #include <iostream> using namespace std; int main() { const int M=20; const int N=10; int field[M][N]={0}; for(int i=0; i<10;i++) cout<<field[M][N]<<endl; return 0; }
1 ответ
+ 4
Nevermind I see what's happening. I'm calling dimension [20][10] when that was not initialized. The arrays dimensions only go up to [19][9].