The following program has some peculiar results regarding the evaluation of 0x787619ce51b4 - 0x787619ce51b0
or equivalently &x[1] - &x[0]
.
What is causing this behavior?
#include <iostream>
#include <string>
int main()
{
int x[3] = {10, 20, 30};
// Here we have the array values
std::cout << x[0] << "\n"; // 10
std::cout << x[1] << "\n"; // 20
std::cout << x[2] << "\n"; // 30
// Here we have the array addresses
std::cout << &x[0] << "\n"; // 0x787619ce51b0
std::cout << &x[1] << "\n"; // 0x787619ce51b4
std::cout << &x[2] << "\n"; // 0x787619ce51b8
// Here we have the math results
std::cout << &x[0] - &x[0] << "\n"; // 0
std::cout << &x[1] - &x[0] << "\n"; // 1
std::cout << &x[2] - &x[0] << "\n"; // 2
// How come we get the result (1) when we do (&x[1] - &x[0])
}