fork download
  1. #include <cstddef>
  2. #include <iostream>
  3.  
  4. int main()
  5. {
  6. int values [5] = { 1, 2, 3, 4, 5 };
  7.  
  8. int * v = values;
  9.  
  10. std::cout << "v address: " << v << ", points to " << *v << '\n' ;
  11.  
  12. ++v;
  13.  
  14. std::cout << "v address: " << v << ", points to " << *v << '\n';
  15. std::cout << "Distance in bytes: " << (std::ptrdiff_t)v - (std::ptrdiff_t)(values) << '\n';
  16. std::cout << "Distance in elements: " << v - values << '\n';
  17.  
  18. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
v address: 0xbf8cc51c, points to 1
v address: 0xbf8cc520, points to 2
Distance in bytes: 4
Distance in elements: 1