#include #include using namespace std; //Search the array for a pair of consecutive equal values. //ptrdiff_t holds the difference between the values of two pointers. int main() { int a[] {0, 10, 20, 30, 40, 40, 50, 60}; const size_t n {size(a)}; //the number of elements in the array //As usual, the last element is a[n-1]. //The next-to-last element is a[n-2]. for (const int *p {a}; p < a + n - 2; ++p) { if (p[0] == p[1]) { const ptrdiff_t i {p - a}; cout << "a[" << i << "] = " << p[0] << "\n"; cout << "a[" << i+1 << "] = " << p[1] << "\n"; } } return EXIT_SUCCESS; }