I have a 2d array and a pointer that points to its first element:
int s[100][100];
int* p;
after reading some value and saving in s:
p=&s[0][0]
Well, now I want to print s-elements by accessing it through p:
for (x = 0; x<m; x++)
{
for (y = 0; y<n; y++)
{
printf("%d ", *(p + sizeof(int)*x*n + y));
}
printf("\n");
}
where m is the number of rows and n is the number of columns. But ... It gives me the wrong answer. I think the expression "p + sizeof (int) * x * n + y" is causing the problem. Please help me fix this. Thank.
source
share