Originally Posted by
learning_grc
Could you please tell me what the code below is exactly doing?
particularly I'm confused about a[i][j]=2.....what is this??
And in last line for which data type they used "%8u" and something
they call "address". what is that address?
Code:
main ()
{
int a[3][2];
int i,j;
for (i=0; j<3; i++)
{
for (j=0; j<2; j++)
{
a[i][j] =2;
}
}
for (i=0; i<3; i++)
{
for (j=0; j<2; j++)
{
printf ("value in array %d\n", a[i][j]);
}
}
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
print ("value in array %d and address is %8u\n", a[i][j], &a[i][j]);
}
}
}
orignal from : java2s.com
First of all lets fix this lousy text setup... and fix some errors...
Code:
int main (void)
{
int a[3][2];
int i,j;
for (i=0; j<3; i++)
for (j=0; j<2; j++)
a[i][j] =2;
for (i=0; i<3; i++)
for (j=0; j<2; j++)
printf ("value in array %d\n", a[i][j]);
for (i=0; i<3; i++)
for (j=0; j<3; j++)
print ("value in array %d and address is %P\n", a[i][j], (void*) &a[i][j]);
return 0;
}
Now you should actually be able to SEE what's going on ....
a[3][2] is a two dimensional array of 3 rows and 2 colums.
However the address should be printed with the %P specifier in that last line.
An address is just that... the location where something is stored...
just like on a street, your street address is where you are stored.