USE C++
Write a function named find that takes a pointer to the
beginning and a pointer to
the end (1 element past the last) of an array, as well as a value.
The function should
search for the given value and return a pointer to the first
element with that value,
or the end pointer if no element was found.
#include<iostream> using namespace std; int* find(int* begin, int* end, int value){ int* p; for(p=begin;p<=end;p++){ if(*p==value){ return p; } } return p; } int main() { int arr[] = {3,2,4,1,7,5,6}; int* result = find(arr,arr+7,4); cout<<*result<<endl; return 0; }
int* find(int* begin, int* end, int value){ int* p; for(p=begin;p<=end;p++){ if(*p==value){ return p; } } return p; }
Get Answers For Free
Most questions answered within 1 hours.