This lab is due by Tuesday, October 11, 2022, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.
Pointer Instructions
The goal of this lab is to gain
familiarity with using the concepts learned on pointers, addresses, and
dynamic memory. Complete the following steps inside your main().
This lab will only be working with pointers on the stack. The next lab will begin
using pointers to the heap.
- Declare an integer named
iNumwith initial value9. - Declare a double named
dNumwith initial value14.25. - Declare two pointers to integers named
pINum1andpINum2. - Declare a pointer to a double named
pDNum. - Assign the address of
iNumtopINum1. - Output the address of
iNumand be sure to identify to the user what you are displaying. There are two ways you can do this; you should do both, to convince yourself they are the same. - Use
pINum1to display the contents ofiNum. - Try to assign the address of
dNumtopINum2. Compile your program. What error message do you see? Comment out this bad line of code, but include the error message as a comment with this line. - Assign the address of
dNumtopDNum. - Output the address and then the contents of
dNum(usingpDNum). - Directly change the value of
iNumto7. - Use
pINum1to output the contents ofiNum. - Assign
pINum2to have the same value aspINum1. Do not referenceiNum; instead use the address stored inpINum1. - Output the address in
pINum2. This should be the same as displayed in step 6. - Output the value pointed to by
pINum2. - Using
pINum2, change the contents ofiNumto12. - Output the contents of
iNumthree times, first usingpINum1, then usingpINum2, theniNumdirectly. In each case, identify what the user is seeing appropriately.
Lab Submission
Submit your main.cpp file(s).
You will submit your solution to this lab with the rest of Set3. Detailed instructions for doing this are posted in Assignment 3.
This lab is due by Tuesday, October 11, 2022, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.