how to determine the address pointed to by a pointer? (theory)
I have this question:
let a double pointer "ptr" point to this address: "0xb786ff12". if I write the following line: ptr + 4. say the final address to which ptr points to.
my attempt: because ptr is a 32 bit double precision pointer, it has 8 bytes; therefore, I have to count using hexadecimal, as follows: (starting from 12)
13, 14, 15, 16, 17, 18, 19, 1a (first set of 8 bytes)
1b, 1c, 1d, 1e, 1f, 21, 22, 23 (second set of 8 bytes)
24, 25, 26, 27, 28, 29, 2a, 2b, (third set of 8 bytes)
2c, 2d, 2e, 2f, 31, 32, 33, 34 (fourth set of 8 bytes)
but it's not correct, because the final result must be 0xb786ff32, 32, not 34.
I know it could be obvious, but I personally find it a little tricky.
Solution 1:
Your counting is wrong! See below:
13, 14, 15, 16, 17, 18, 19, 1a (first set of 8 bytes)
1b, 1c, 1d, 1e, 1f, 20, 21, 22 (second set of 8 bytes)
23, 24, 25, 26, 27, 28, 29, 2a, (third set of 8 bytes)
2b, 2c, 2d, 2e, 2f, 30, 31, 32 (fourth set of 8 bytes)
#f is followed by (#+1)0, not by (#+1)1, as in your sequence (1f was followed by 21, and 2f was followed by 31)