2D looping help

Can somebody help me understand the looping process for 2d arrays?

int main()
{
int a[3][3], x[3], y[]={3,4,5,6}, z=0, r, c;
int i=1;
cout<<" r c a i"<<endl;
for (r=1; r<=2; r++){
for (c=1; c<=2; c++){
a[r][c]=r*c*i;//what is going on here?
i++;
}
}
for (c=1; c<=2; c++){
for (r=1; r<=2; r++){
i--;
cout<<" "<<r<<" "<<c<<" "<<a[r][c]<<" "<<i<<endl;
}}

Can someone explain how all these spots in the 2d array are assigned?
I'm not sure what exactly you're asking.
The line in question assigns the result of r*c*i to the element (r,c) in the array a.
can you explain the order of reassignment?

do you increment i and c and then reassingn?

I am confused as to what order the for loops move, from inside out or from outside in?
If you could do the first few reassignments that would be great. thanks a lot
bump
Well, for each iteration of a for loop, its entire body is executed.
That includes other for loops that it might contain.

So your first loop starts with r=1.
Its body contains another for loop, which goes through two iterations with c=1 and c=2:
a[1][1]=1*1*1; i++;
a[1][2]=1*2*2; i++;
With that, the next iteration of the outer loop is started (now with r=2).
a[2][1]=2*1*3; i++;
a[2][2]=2*2*4; i++;
thanks a lot.. thanks!
Topic archived. No new replies allowed.