#include #include #include using namespace std; int main() { int a[] = {10, 20, 30, 40, 50}; size_t n = sizeof a / sizeof a[0]; //n is 5 int *p1 = a; //point to the 10 int *p2 = a + 4; //point to the 50 ptrdiff_t d1 = p2 - p1; //d1 is 4 p1 += d1; //Now p1 points to the 50. vector v(a, a + n); vector::size_type s = v.size(); //s is 5 vector::iterator it1 = v.begin(); //refer to the 10 vector::iterator it2 = v.begin() + 4; //refer to the 50 vector::difference_type d2 = it2 - it1; //d2 is 4 it1 += d2; //Now it1 refers to the 50. return EXIT_SUCCESS; }