Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Coded in C ointers: create a 1D array of integers which has 5 elements. You may initialize the array with the following alues: {1,2,3,4,5}. Then,
Coded in C
ointers: create a 1D array of integers which has 5 elements. You may initialize the array with the following alues: {1,2,3,4,5}. Then, perform the following operations in order: a. Create an integer pointer which is initialized to store the address of the last element of the array. b. Print out the second and fourth elements of the array using only the pointer. Do not modify the pointer's stored address. Do not use the array variable in your print statement. Hints: Use the dereferencing notation. You can dereference different addresses by adding a scalar value to the pointer in parenthesis. The following statement will dereference the address which is one array element beyond the stored pointer address: " (ptr+1) ". c. On a new line, print the address of the third element of the array using the pointer. Do not modify the pointer's stored address. Do not use the array variable in your print statement. Hints: You simply need to add or subtract a value from the pointer's stored address and print it. You can confirm your answer is correct by also printing out the address of the array's third element using the array variable itself, e.g.: \&arr[2]. d. Modify the pointer's stored address to now be the starting address of the array, without using the array variable. You do not need to print anything. Hints: A simple mathematical operation on the pointer is all that is needed here. Again, you can print the pointer's value and the array's starting address directly (using the array) to confirm your answer. e. Modify the last element of the array to hold the value 77 , using only the pointer. Hints: The expression needed here is similar to what is needed in part B, except the dereferenced pointer (with offset) is on the left-hand side of the equal sign. You can print out the last element of the array directly to confirm it was modifiedStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started