I have the memory address of one int *
:0xbfde61e0. I also have another memory address (that is also int *
. How can I calculate the difference between the two to use as an offset between the two locations?
Its as easy as it sounds.
int a = 5;
int b = 7;
int *p_a = &a;
int *p_b = &b;
int difference = p_b - p_a;
Keep in mind that this will give the difference as a multiple of sizeof(int)
. If you want the difference in bytes, do this:
int differenceInBytes = (p_b - p_a) * sizeof(int);
Without specific code or a specific application, I can't get more detailed than that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With