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

f. Print the elements of array values using pointer/offset notation with the arr

ID: 3919656 • Letter: F

Question

f. Print the elements of array values using pointer/offset notation with the array name as the pointer. g. Print the elements of array values by indexing the pointer to the array h. Refer to element 5 of array values using array index notation, pointer/offset notation with the array name as the pointer, pointer index notation, and pointer/offset notation. i. What address is referenced by vPtr 3? What value is stored at that location? . Assuming vPtr points to values [ 4], what address is referenced by vPtr - 4? What value is stored at that location?

Explanation / Answer

Answer f:

for (i = 0; i < SIZE; i++)
printf ("%d ", *(values + i));

Explanation:
Using for loop along with the pointer to print all the elements in an array.


Answer g:

for (i = 0; i < SIZE; i++)
printf ("%d ", vPtr[i]);

Explanation: Printing the elements of array by indexing the pointer

Answer i: 1002512 and 8
Explanation:
Since values[0] is stored at 1002500 and vPtr + 3 refers to values[3], and an integer is 4 bytes long, the address that is referenced by vPtr + 3 is 1002500 + 3 * 4 = 1002512. Since we are referring to values[3] we are referring to the fourth element in the values array, thus the value we are referring to is 8.

Answer j : 1002500 and 2
Explanation:
Since vPtr point to values[4], the address stored in vPtr is 1002500 + 4 * 4 = 1002516 (since each element is an integer using 4 bytes). vPtr -= 4 decrements vPtr by 4 elements of the array, with a new value of 1002516 - 4 * 4 = 1002500. This is the address of the first element of the array, which is 2.