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
iNum
with initial value9
. - Declare a double named
dNum
with initial value14.25
. - Declare two pointers to integers named
pINum1
andpINum2
. - Declare a pointer to a double named
pDNum
. - Assign the address of
iNum
topINum1
. - Output the address of
iNum
and 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
pINum1
to display the contents ofiNum
. - Try to assign the address of
dNum
topINum2
. 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
dNum
topDNum
. - Output the address and then the contents of
dNum
(usingpDNum
). - Directly change the value of
iNum
to7
. - Use
pINum1
to output the contents ofiNum
. - Assign
pINum2
to 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 ofiNum
to12
. - Output the contents of
iNum
three times, first usingpINum1
, then usingpINum2
, theniNum
directly. 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.