Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

int x[]{ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }; int *xPtr1{ x }; int numb

ID: 3815021 • Letter: I

Question

int x[]{ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
int *xPtr1{ x };
int number{ 0 };

cout << "Enter a positive integer: ";

cin >> number;

Requirements:

1. Using POINTER/OFFSET notation, write the statement below that will add a number entered by a user to xPtr1

2. Note that to receive credit for this problem, you MUST use Pointer/Offset notation in your code.
3. Note also that you are changing the value of the pointer, not the value of the data pointed to by the pointer.

4. Write the statement below that will add the number entered by the user to the VALUE stored at the pointer's current location.

Solve this question in C++. Thank you!

Explanation / Answer

#include <iostream>
#include <cstdlib>
using namespace std;

int main(){

   int x[] = { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
   int *xPtr1 = x;
   int number = 0;
   cout << "Enter a positive integer: ";
   cin >> number;

   // adding number in xPtr1
   xPtr1 = xPtr1 + number;

   *(xPtr1) = *xPtr1 + number; // adding number in value pointed by xPtr1

   return 0;
}