#include #include using namespace std; /** * Returns a ptr to the first instance of an element x in an arr arr of length n. * If not found, return NULL; */ int* find(const int arr[], int n, int x); /** * Prints out array arr of length n. */ void printArray(const int arr[], int n); int main() { const int ARRAY_SIZE = 9; int x[ARRAY_SIZE] = {1, 2, 3, 4, 5, 4, 3, 2, 1}; { int *ptr = find(x,ARRAY_SIZE,3); if (ptr != NULL) { *ptr = 10; cout << "Replaced 3 with 10: "; printArray(x,ARRAY_SIZE); cout << endl; }else { cout << 3 << " not found" << endl; } } { int *ptr = find(x,ARRAY_SIZE,3); if (ptr != NULL) { *ptr = 100; cout << "Replaced 3 with 100: "; printArray(x,ARRAY_SIZE); cout << endl; } else { cout << 3 << " not found" << endl; } } { int *ptr = find(x,ARRAY_SIZE,3); if (ptr != NULL) { *ptr = 1000; cout << "Replaced 3 with 1000: "; printArray(x,ARRAY_SIZE); cout << endl; } else { cout << 3 << " not found" << endl; } } } void printArray(const int arr[], int n) { cout << "{ "; for (int i=0;i