Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 :

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)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading