CSCI 200 - Fall 2024
Foundational Programming Concepts & Design

Lab 2B - Pointers: Addresses & Values

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.

  1. Declare two integers named iNum and iNum2 with initial values 4 and 5 respectively.
  2. Declare two pointers to integers named pINum1 and pINum2 both with initial value nullptr.
  3. Assign the address of iNum to pINum1.
  4. Assign the address of iNum2 to pINum2.
  5. 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.
  6. 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.
  7. Use pINum1 to display the value of iNum.
  8. Use pINum2 to display the value of iNum2.
  9. Directly change the value of iNum to 6.
  10. Use iNum to output the value of iNum.
  11. Use pINum1 to output the value of iNum.
  12. Use pINum1 to change the value it is pointing at to 7.
  13. Use iNum to output the value of iNum.
  14. Assign pINum2 to have the same value as pINum1. Do not reference iNum; instead use the address stored in pINum1.
  15. Output the value of pINum2.  This should be the same as displayed in step 5.
  16. Output the value pointed to by pINum2.
  17. Using pINum2, change the value it is pointing at to 8.
  18. Output the value of iNum three times, first using pINum1, then using pINum2, then iNum directly. In each case, identify what the user is seeing appropriately.
  19. Output the value of iNum2. It should remain unchanged from the initial value.
  20. Declare a pointer to a double named pDNum with initial value nullptr.
  21. Try to assign the address of iNum to pDNum. 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.
  22. Try to assign the value of pINum1 to pDNum. 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.
  23. Declare a double named dNum with initial value 14.25.
  24. Assign the address of dNum to pDNum.
  25. Output the address and then the value of dNum using pDNum for both.
  26. Try to assign the value pINum1 is pointing at to the value pDNum is pointing at.
  27. Output the value of dNum two times, first using dNum then using pDNum.

Grading Rubric


Your submission will be graded according to the following rubric:

PointsRequirement Description
0.70Fully meets specifications
0.15Submitted correctly by Friday, September 20, 2024, Before Class
0.15Best Practices and Style Guide followed
1.00Total 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.