I started learning arrays in C++ and came over a little side note in the book talking about 2D arrays in breif.
I tested it out and i was amazed that it could give the programmer the ability to store data or information and lay it out infront of him in a spread sheet format.
In a normal array to access elements i would simply do this:
int matrix[2] = { 1, 15};
But in 2D arrays :The only way it tells me to actually acces elements is by using a loop:
int fly[2][2];
int i = 0;
int n=0;
for(i=0; i<2; i++){
for (n=0; n<2; n++){
fly[i][n] =0;
}
}
for(i=0; i<2; i++){
for (n =0; n<2; n++){
cout << fly[i][n]<< endl;
}
}
I have tried accessing elements the old way:
int fly[2][2] = { 0};
but i noticed that this changes all the elements to 0
So..
Can anyone explain when i try accessing this 2D array like this all the elements change.
Is there another way to access 2D array elements without using a loop.
Thank you all.
flyrepresent here.XandYcoordinates?RowsandColumns?) and create an array of those data objects. Simply accessing unnamed dimensions can be a mess for comprehensibility down the line.