Hello/Hi,
I m new to this pool of C.
I wass just reading a book named "C TUTOR" this book is gr8..
but i cannot understand the subscripts of 2D arrays...
I find them pretty hard..
Plz tell me wat exactly the below programme mean of suggest me some simple books or sites...
Plz simple and breif ...
Thanks in advance..

main( )
{
      int i,j;
      int big[8][8],huge[25][12];
      for (i = 0;i < 8;i++)
            for (j = 0;j < 8;j++)
                   big[i][j] = i * j; /* This is a multiplication table */
      for (i = 0;i < 25;i++)
              for (j = 0;j < 12;j++)
                    huge[i][j] = i + j; /* This is an addition table */

big[2][6] = huge[24][10] *22;
big[2][2] = 5;
big[big][2][2]...big[2][2]. = 177; /* this is big[5][5] = 177; */

for (i = 0;i < 8;i++) {
                 for (j = 0;j < 8;j++)
                             printf("%5d ",big[i][j]);
                                printf("\n"); /* newline for each increase in i */
     }
}

This programme shows no errors and works perfectly but i cannot understand the mechanism behind that plz help me...
Its urjent....
plz,
Tell me the entire programme function...
Thnx....

Salem commented: 10 posts, no code tags, COOKIE TIME!!!!! -4

Think of a 2 dimensional array like a checkers board, which has rows and columns of squares. Or you could think in terms of an electronic spreadsheet. In a 2d array the first dimension represents the rows and the second dimension represents the columns.

You might declare a spreadsheet that has 10 rows of 3 columns each like this:

int array[10][3];

and to reference row 3 column 2 array[3][2] = 0; That's really all there is to it. Just remember that C language counts rows and columns starting with 0, not 1, so the columns are numbered 0, 1 and 2 and the rows are 0, 1, 2, ... 9.

If you are confused about the following line, don't be. All of us including the compiler should be confused about it since it has syntax error and the comments don't match either big[big][2][2]...big[2][2]. = 177; /* this is big[5][5] = 177; */ :)

On more serious note let's see your code

for (i = 0;i < 8;i++)
   for (j = 0;j < 8;j++)
      big[i][j] = i * j; /* This is a multiplication table */

This multiplies the indices i and j, and stores the result in the big[j] location. For example if i = 2, and j=3, then i*j = 6 so it will assign 6 to the array element big[2][3].

for (i = 0;i < 25;i++)
   for (j = 0;j < 12;j++)
      huge[i][j] = i + j; /* This is an addition table */

This does the same thing except it adds instead of multiplying. big[2][6] = huge[24][10] *22; This multiplies the value stored in huge[24][10] by 22 and stores it in big[2][6] location. The value of huge[24][10] should be 24+10 = 34 because it was computed in the second set of nested loops above by adding the indices together. So multiply it by 22 you get 34*22 = 748. This gets stored in big[2][6].

Oh now that I look at the code where the error is, the ... must have been a comma ][ so assuming that's the case the statement should look like

big[2][2] = 5;
big[ big][2][2] ][ big[2][2] ] = 177; /* this is big[5][5] = 177; */

Now pay close attention to the way the statement is written. Notice that it is using big[2][2] as index for both dimensions and the value of big[2][2] is set to 5 in the statement before it. So it is essentially doing big[5][5] = 177

Hope this helps.

Hello/Hi,
I m new to this pool of C.
I wass just reading a book named "C TUTOR" this book is gr8..
but i cannot understand the subscripts of 2D arrays...
I find them pretty hard..
Plz tell me wat exactly the below programme mean of suggest me some simple books or sites...
Plz simple and breif ...
Thanks in advance..

main( )
{
      int i,j;
      int big[8][8],huge[25][12];
      for (i = 0;i < 8;i++)
            for (j = 0;j < 8;j++)
                   big[i][j] = i * j; /* This is a multiplication table */
      for (i = 0;i < 25;i++)
              for (j = 0;j < 12;j++)
                    huge[i][j] = i + j; /* This is an addition table */

big[2][6] = huge[24][10] *22;
big[2][2] = 5;
big[big][2][2]...big[2][2]. = 177; /* this is big[5][5] = 177; */

for (i = 0;i < 8;i++) {
                 for (j = 0;j < 8;j++)
                             printf("%5d ",big[i][j]);
                                printf("\n"); /* newline for each increase in i */
     }
}

This programme shows no errors and works perfectly but i cannot understand the mechanism behind that plz help me...
Its urjent....
plz,
Tell me the entire programme function...
Thnx....

above programme is right,

but you have to maintain the indentation in the programme.

above programme is right,

but you have to maintain the indentation in the programme.

After you posted that unformatted code in another thread you have the gall to mention indentation here? Practice what you preach.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.