Question: C++ with comments Question 1 Use the following code snippet as the basis for a program to test all possible combinations of pointer manipulation .

C++ with comments

Question 1

Use the following code snippet as the basis for a program to test all possible combinations of pointer manipulation. Each of the 10 combinations must be tested separately since the pointer may move and array values may be changed:

int X[] = { 3, 7, 11, 17, 23 };

int * xPtr = & X[2];

cout << "Array content prior to pointer manipulation "; cout << X[1] << ' ' << X[2] << ' ' << X[3] << ' ' << xPtr << " : " << *xPtr << endl;

// replace AAA in the following statement with selection from list of 10 pointer actions below, one at a time

cout << AAA << endl;

cout << endl << "Array content after ptr manipulation" << endl;

cout << X[1] << ' ' << X[2] << ' ' << X[3] << ' ' << xPtr << " : " << *xPtr << endl;

Generate an extremely concise summary report explaining the result of each of these pointer actions when inserted in place of AAA above. The report must identify: were any array values changed and, if the pointer moved, where and when it moved, and what value was output. The summary should group together any commands that produce identical results. The summary must be less than 100 words total. Its possible some of these combinations wont compile.

*++xPtr

(*++)xPtr

++*xPtr

++(*xPtr)

(++*)xPtr

*xPtr++

(*xPtr)++

*(xPtr)++

*(xPtr++)

*(++xPtr)

Question 2

Create an array of 100 integers, with values randomly generated to be in the range of -73 to +124 (include both extremes).

1. Using standard array notation, print all values in the array on one line, separated by a space
2. Using array offset notation, print all values in the array, from last index to first, on one line, each separated by a space
3. Using pointer notation, print all negative values on one line, each separated by a space
4. Using pointer offset notation, print all positive (>=0) values on one line, each separated by a space

Reminder:

array notationmyArray[ x ];

array offset notation*(myArray + x);

pointer notation* arrayPtr;

pointer offset notation*(arrayPtr + x);

Question 3

Starting with the shortest possible C++ program, modify your program so that it will display to the console the name of the executable that is running and each argument value passed into main. You must have at least two arguments.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!