Consider the following piece of code :
int main() {
long long * x = new long long [10]; // array of long long
long a = (long) x; // address of first element
long b = (long) (x+1); //address of second element
long c = b - a ; // first difference
long d = (long) ((x+1) - x); // second difference
std::cout << c << std::endl ;
std::cout << d << std::endl ;
return 0;
}
The program out puts first 8, then 1 . I have got some understanding of pointers, and how to use them. I have come to the conclusion that adding +1 to a raw pointer value will increment it by the size of the thing it is pointing. This feature is unfamiliar to me.
So my question is why do pointer types behave like this? What would be the use of such behaviour ?