Short answer
The address of the pointer will be incremented by sizeof(T)
where T
is the type pointed to. So for an int
, the pointer will be incremented by sizeof(int)
.
Why?
Well first and foremost, the standard requires it. The reason this behaviour is useful (other than for compatibility with C) is because when you have a data structure which uses contiguous memory, like an array or an std::vector
, you can move to the next item in the array by simply adding one to the pointer. If you want to move to the nth item in the container, you just add n.
Being able to write firstAddress + 2
is far simpler than firstAddress + (sizeof(T) * 2)
, and helps prevent bugs arising from developers assuming sizeof(int)
is 4 (it might not be) and writing code like firstAddress + (4 * 2)
.
In fact, when you say myArray[4]
, you're saying myArray + 4
. This is the reason that arrays indices start at 0; you just add 0 to get the first element (i.e. myArray points to the first element of the array) and n to get the nth.
What if I want to move one byte at a time?
sizeof(char)
is guaranteed to be one byte in size, so you can use a char*
if you really want to move one byte at a time.