Ven Varu Ven Varu - 1 year ago 56
C Question

How does this hexadecimal arithmetic work?

I'm learning C pointers. I have incremented a double pointer by 1, as follows:

before ->

ptr_double =0x0128

then I incremented it by 1, and then the address stored in ptr_double increases by 8 bytes, that is
+ 8 which gives

I'm unable to understand how arithmetically

I know this is probably a basic question, but I'm having difficulty understanding this. Can someone please explain this to me?

Answer Source

I assume you have a pointer to double like double* ptr_double;, which has its value 0x128, then you increment it ++ptr_double; (which makes the pointer jump with a sizeof(double), which in this case is 8). The address is in hexadecimal (base 16), so

0x128 + 0x8 = 0x130

Remember that hexadecimals belong to the range 0,1,...,9,A,B,C,D,E,F, so 0x8 + 0x8 = 10.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download