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

Change this to off base notation int *arr = new int[20]; for( int i = 0; i < 20;

ID: 3555751 • Letter: C

Question

Change this to off base notation

int *arr = new int[20];

for( int i = 0; i < 20; i++)

{

       cout <<"Enter the value for index " << i <<" in the array: ";

       cin >> arr[i];

}

B) For each of the following, write C++ statements that perform the specified task. Assume the following: const int SIZE = 5;   Must use SIZE wherever a size is required.

Also assume that unsigned integers are stored in 2 bytes and that the base address of the array is at location 1002500 in memory. Remember do not create a program or a cpp file.

i) Declare an array of type unsigned int called values with 5 elements and initialize the elements to the even integers from 2 to 10.

           

ii) Declare a pointer vPtr that points to an object of type unsigned int.

           

iii) Display the elements of array values using array subscript notation.

iv) Show two different ways of assigning the base address of array values to pointer variable vPtr.

v) Using vPtr with base/offset notation display the elements of array values.

vi) Display the elements of array values using base/offset notation with the array name as the pointer.

vii) Display the elements of array values using array notation with vPtr.

viii) Refer to the fifth element of values using array subscript notation, base /offset notation with the array name as the pointer, array notation with vPtr, and base /offset notation with vPtr.

ix) What address is referenced by vPtr + 3? (This means the actual memory address) What value is stored at that location?

x) Assuming vPtr points to values[ 4 ], what address is referenced by vPtr -= 4? (This means the actual memory address) What value is stored at that location?

xi) Assume that vPtr again points to the base address of the array. Using array subscript notation, base/offset notation with the array name as the pointer, array notation with vPtr, and pointer/offset notation with vPtr, add 3 to the value in the first element.

xii) Using array subscript notation, base/offset notation with the array name as the pointer, array notation with vPtr, and pointer/offset notation with vPtr, add 3 to the value in the 3rd element and display that number. (Do not modify the value in the array).

xiii) How would you verify the size of an unsigned int on a system?

C) Given the following:

            short data[ 15 ] = { 5, 2, 3, 4, 1, 8, 13, 12, -3 };

            and:

Evaluate the following:

1)  data + 4

2) *( data + 4 )

3) *data + 4

4)   *( data + *( data + 2 ) )

D) Given the following:

            int*** p;

       What is the data type of each of the following:

1)p 2) *p 3) **p 4) ***p

Explanation / Answer

Dear,

a) Define the variable values with unsigned int and initialize the even integers from 2 to 10. It can be done in two ways

const int SIZE = 5;
unsigned int values[SIZE] = {2, 4, 6, 8, 10};

               or

const int SIZE = 5;
unsigned int values[SIZE];
for (int i = 1; i <= 5; i++)
    values[i-1] = 2 * i;

b) The following pointer vPtr that points to the object of the type unsigned int.
         unsigned *vPtr;

c)Print the elements of the array values using the array subscript notation.
    for(int i=0; i<SIZE; i++)
       cout<<setw(4)<<values[i];

d) Assign the starting address of the array values to pointer variable vPtr
   vPtr = values;
   vPtr = &values[0];

e) Print the elements of array values using pointer/offset notation.

for(int i=0; i<SIZE; i++)
    cout<<setw(4)<<*(vPtr + i);


f) Print the elements of array values using pointer/offset notation with the array name as a pointer.

   for(int i=0; i<SIZE; i++)
   cout<<setw(4)<<*(values + i);

g)Print the elements of the array values using subscripting the pointer to the array.
    for(int i=0; i<SIZE; i++)
   cout<<setw(4)<<vPtr[i];

h)The fifth element of values using array subscript notation, pointer/offset notation with the array name as the pointer, pointer subscript notation and pointer/offset notation.

    values[4], *(values+4), vPtr[4],*(vPtr+4).

i) On my machine If 0012FEB8 is the address of the values[0], then vPtr + 3 will refer to the address 0012FEC4 and the value stored at that location is 8

According to the given memory,
If 1002500 is the address of the values[0], then vPtr + 3 will refer to the address 1002506 and the value stored at that location is 8

j) On my machine If 0012FEC8 is the address of the values[4], then vPtr -= 4 will refer the address 0012FEB8 and the value stored at that location is 2

According to the given memory, If 1002500 is the address of the values[0], then
vPtr + 3 will refer to the address 1002506 and the value stored at that location is 8.

C)

1)  data + 4 =100258

2) *( data + 4 ) = 1

3) *data + 4

4)   *( data + *( data + 2 ) ) =3

D) All the above four are of type integers.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote