I am confused on incrementing pointers for arrays and then measuring the difference in bytes for the pointer locations.
I understand that a pointer *p
will increment by the datatype's size when moving though a multi-dimensional array. However, when an array, thisArray
is used:
int thisArray[ 7 ][ 4 ];
How should thisArrray + 1
be evaluated? Do I increment both rows and columns?
I want to know by by how many bytes apart will these pointers will be in memory.
I know the exact answer will be platform dependent. I am seeking the method of solution, not the exact answer.
Since I can't format code in the comments: I am putting it here:
// Using sizeof
#include <stdio.h>
int main(void) {
int tbl[ 7 ][ 4 ];
// Size of tbl
int x = sizeof(*tbl);
printf ( "%d\n" , x);
// Size of tbl + 1;
int y = sizeof(*tbl+1);
printf( "%d\n", y);
//Size apart in bytes
int z = y - x;
printf("%d\n", z);
return 0;
}