For each of the following, write C++ statements that perform the specified task.
ID: 3657680 • Letter: F
Question
For each of the following, write C++ statements that perform the specified task. Assume that SIZE has been defined as 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. unsigned int values[SIZE] = {2, 4, 6, 8, 10}; unsigned int *vPtr; 1. Using vPtr with base/offset notation display the elements of array values. 2. Display the elements of array values using array notation with vPtr.Explanation / Answer
// given to us
unsigned int SIZE = 5;
unsigned int values[SIZE] = {2, 4, 6, 8, 10};
unsigned int *vPtr;
// base offset notation
vPtr = values;
int i;
for(i = 0; i < SIZE: i++)
{
unsigned int array_element = *(vPtr+i); // dereference at proper location
cout << array_element << endl;
}
// array notation
vPtr = values;
int i;
for(i = 0; i < SIZE: i++)
{
unsigned int array_element = vPtr[i];
cout << array_element << endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.