Using C++ Declare an integer pointer. Then declare an array of 10 integers and a
ID: 3826114 • Letter: U
Question
Using C++ Declare an integer pointer. Then declare an array of 10 integers and ask the user for the value of the elements of the array. Point your integer pointer to the first element of the array. Use the integer pointer to parse through the array elements and find the maximum value. Don't use the array itself for passing and finding the maximum. Display the max value and it's memeory address, as well as the memory address at the start of the array. Using C++ Declare an integer pointer. Then declare an array of 10 integers and ask the user for the value of the elements of the array. Point your integer pointer to the first element of the array. Use the integer pointer to parse through the array elements and find the maximum value. Don't use the array itself for passing and finding the maximum. Display the max value and it's memeory address, as well as the memory address at the start of the array. Using C++Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
int *ptr;
int arr[10];
cout << "enter 10 intergers:";
for (int i = 0; i < 10; i++)
cin >> arr[i];
ptr = &arr[0];
int big = *(ptr+0);
int max_index = 0;
for (int i = 1; i < 10; i++)
{
if (*(ptr + i)>big)
{
big = *(ptr + i);
max_index = i;
}
}
cout << "The Max value:" << *(ptr + max_index)<<endl;
cout << "The address of location:" << (ptr + max_index) << endl;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.