I'm new to C++, and I've started to learn arrays. Here is my program on arrays:
#include <iostream>
using namespace std;
int main(){
int arr[3][3];
for (int i = 0; i<3; i++){
for (int j = 0; j<3; j++){
cout << "Enter " << j + 1 << " element of " << i + 1 << " row:";
cin >> arr[i][j];
}
}
for (int i = 0; i<3; i++){
for (int j = 0; j<3; j++){
cout << j + 1 << " element of " << i + 1 << "row:";
cout << arr[i][j] << endl;
}
}
system("pause");
return 0;
}
I know that array's first index in C++ is zero. So, logically, an array arr[3][3]should have 4 * 4 = 16 elements, right? But practically, if I change 3 to 4 in my for cycles, I'll get out of range error. Why does it happen? Am I missing something?
So, how much elemets are in arr[3][3]?
