Write a C++ program that creates an integer array of size 10.
- Then, get the array values as input from the user but save them in the array using a pointer.
- Then, print those values using the pointer.
- Then, ask the user to search any value and perform a search operation using the pointer
#include <iostream>
using namespace std;
int main(){
int arrElements[10];
int *ptr;
int searchElement;
bool flag = true;
cout << "Enter the values. " << endl;
for (int i = 0; i < 10; i++)
{
cin >> arrElements[i];
}
ptr = arrElements;
cout << "\nThe values in array are. ";
for (int i = 0; i < 10; i++)
{
cout << *(ptr + i) << " ";
}
cout << "Enter element you want to search. ";
cin >> searchElement;
for (int i = 0; i < 10; i++)
{
if (searchElement == *(ptr + i))
{
cout << "The element found at index. " << i;
flag = false;
}
}
if (flag)
{
cout << "Element not found (:<(";
}
return 0;
}