#include #include #include #include //for find using namespace std; int main() { int a[] = {10, 20, 30, 40, 50}; size_t n = sizeof a / sizeof a[0]; vector v(a, a + n); int *p1 = find(a, a + n, 20); int *p2 = find(a, a + n, 40); ptrdiff_t d1 = p1 - p2; cout << "The distance between 20 and 40 is " << d1 << ".\n"; p2 += d1; cout << "Now p2 points to " << *p2 << ".\n\n"; vector::iterator it1 = find(v.begin(), v.end(), 20); vector::iterator it2 = find(v.begin(), v.end(), 40); vector::difference_type d2 = it1 - it2; cout << "The distance between 20 and 40 is " << d2 << ".\n"; it2 += d2; cout << "Now it2 refers to " << *it2 << ".\n"; return EXIT_SUCCESS; }