C++ Question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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; }

15th Aug 2017, 3:53 AM
21kHzBANK21kHZ
21kHzBANK21kHZ - avatar
1 Answer
+ 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].
15th Aug 2017, 3:57 AM
21kHzBANK21kHZ
21kHzBANK21kHZ - avatar