I was writing a program in which i used a 5x5 array, and i actually came up with a bug.
In order to find it, I tried simplifying the program, and writing another one instead, in which i just wanted to simply show the numbers 1 to 25 using arrays.
#include <iostream>
#include <conio.h>
using namespace std;
main()
{
long int a[4][4];
int m=1;
for(int i=0;i<5;i++)
{for(int j=0;j<5;j++)
{a[i][j]=m;
m=m+1;
}
}
for(int i=0;i<5;i++)
{for(int j=0;j<5;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
getch();
}
And what i actually got was this:
1 2 3 4 6
6 7 8 9 11
11 12 13 14 16
16 17 18 19 21
21 22 23 24 25
However, when i tried a different thing and put a cout<<a[i][j]; after a[i][j]=m; and deleted the second part, i got it correct.
Am i missing something here?