LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   error code for pointers and 2-Dimensional arrays (https://www.linuxquestions.org/questions/programming-9/error-code-for-pointers-and-2-dimensional-arrays-214475/)

shams 08-06-2004 09:05 PM

error code for pointers and 2-Dimensional arrays
 
hi,
This is the code for pointers and 2-Dimensional arrays :
#include <stdio.h>
main()
{
int s[5][2]={
{1235,56},
{1212,33},
{1434,80},
{1312,78}

};

int i, j;

for(i=0;i<=3;i++)
printf(" Address of %d th 1-D array=%u\n",s[i],s[i]);

}
the output of this program suppose to be:
Address of 0 th 1-D array=3221222672
Address of 1 th 1-D array=3221222680
Address of 2 th 1-D array=3221222688
Address of 3 th 1-D array=3221222696
but it is:
Address of -1073744624 th 1-D array=3221222672
Address of -1073744616 th 1-D array=3221222680
Address of -1073744608 th 1-D array=3221222688
Address of -1073744600 th 1-D array=3221222696
plz point me where is the error.

Hko 08-06-2004 10:00 PM

Change this:
Code:

printf(" Address of %d th 1-D array=%u\n", s[i],s[i]);
to this:
Code:

printf(" Address of %d th 1-D array=%u\n", i, s[i][1]);


All times are GMT -5. The time now is 04:36 PM.