Ven Varu Ven Varu - 2 months ago 19
C Question

Increment double pointer by 1

I'm learning c pointers. There I have incremented a double pointer by 1. I have as follows

before ->

ptr_double =0x0128


then I incremented it by 1.

So address stored in ptr_double increases by 8 bytes , That is
0x0128
+ 8 which gives
0x0130
, But I'm unable to understand how arithmetically
0x0130
comes.

Please be kind enough to explain me. I know it's a stupid question. But I couldn't understand so far.

Answer

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.

Comments