Adding / subtracting a pointer does not move with just one byte - it moves by the size of the type of object being pointed to.
That is (assuming 4-byte integers)
int *p = 0x00004
int *q = p+1;
assert(q == 0x00008)
Basically, this is the same as if you were using the operator index:
int *q = &p[1]
If you want to increase the pointer by one, draw it on unsigned char *. As you did, you were rewriting memory that was not part of a variable aand might have been rewriting existing data for something else.
source
share