This lab is due by Friday, September 20, 2024, Before Class.
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.
Jump To: Rubric Submission
The goal of this lab is to gain
familiarity with using the concepts of pointers and addresses. Complete the following steps inside your main()
.
This lab will only be working with pointers on the stack.
- Declare two integers named
iNum
andiNum2
with initial values4
and5
respectively. - Declare two pointers to integers named
pINum1
andpINum2
both with initial valuenullptr
. - Assign the address of
iNum
topINum1
. - Assign the address of
iNum2
topINum2
. - 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. - Output the address of
iNum2
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 value ofiNum
. - Use
pINum2
to display the value ofiNum2
. - Directly change the value of
iNum
to6
. - Use
iNum
to output the value ofiNum
. - Use
pINum1
to output the value ofiNum
. - Use
pINum1
to change the value it is pointing at to7
. - Use
iNum
to output the value ofiNum
. - Assign
pINum2
to have the same value aspINum1
. Do not referenceiNum
; instead use the address stored inpINum1
. - Output the value of
pINum2
. This should be the same as displayed in step 5. - Output the value pointed to by
pINum2
. - Using
pINum2
, change the value it is pointing at to8
. - Output the value of
iNum
three times, first usingpINum1
, then usingpINum2
, theniNum
directly. In each case, identify what the user is seeing appropriately. - Output the value of
iNum2
. It should remain unchanged from the initial value. - Declare a pointer to a double named
pDNum
with initial valuenullptr
. - Try to assign the address of
iNum
topDNum
. 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. - Try to assign the value of
pINum1
topDNum
. 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. - Declare a double named
dNum
with initial value14.25
. - Assign the address of
dNum
topDNum
. - Output the address and then the value of
dNum
usingpDNum
for both. - Try to assign the value
pINum1
is pointing at to the valuepDNum
is pointing at. - Output the value of
dNum
two times, first usingdNum
then usingpDNum
.
Grading Rubric
Your submission will be graded according to the following rubric:
Points | Requirement Description |
0.70 | Fully meets specifications |
0.15 | Submitted correctly by Friday, September 20, 2024, Before Class |
0.15 | Best Practices and Style Guide followed |
1.00 | Total Points |
Lab Submission
Always, always, ALWAYS update the header comments at the top of your main.cpp
file. And if you ever get stuck, remember that there is LOTS of help available.
Zip together your main.cpp, Makefile
file(s) and name the zip file L2B.zip
. Upload this zip file to Canvas under L2B.
This lab is due by Friday, September 20, 2024, Before Class.
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.