Here is one way of assigning value to an array
char s[2][2];
s[0][0] = 1;
s[0][1] = 2;
s[1][0] = 3;
s[1][1] = 4;
cout << s[0][2];
output of this will be some garbage and it keeps changing. But strange thing happens when I do this
char s[2][2];
for (int i = 0, j = 0; i <= 2; i++){
if(i == 2)
{
j++;
i = 0;
}
if(j == 2) break;
cin >> s[j][i];
}
cout << s[0][2];
so as I give input as
1 2
3 4
the output was 3
?
First of all shouldn't it complain that we are using array beyond its index and secondly why so much difference?