Question: 2. Pointers and Dynamic Memory A pointer is a special-type of variable that points to a stored variable. It does so by storing the address
2. Pointers and Dynamic Memory A pointer is a special-type of variable that points to a stored variable. It does so by storing the address of the variable being pointed at. In this program, we will learn working with pointers and dynamic memory In your main function Declare an integer my int initialized with value 10 Declare two integer pointer variables my iptr and my iptr2 Assign the address of my int variable to the pointer my iptr Display the following on the screen: The value of the variable using the variable name The address of the variable using the variable name The address of the variable using the pointer The value of the variable using the pointer o o o o Using the pointer my iptr, update stored integer value from 10 to 15 Display the value of the integer using the variable name Did the value of my int change to 15? Think why, it did or did not change Now we will use new and delete to implement dynamic memory in the program. Add the following functionalities in your code Update your integer pointer my iptr by allocating new memory to it. .Using the pointer variable, assign a value of 20 to it Display the value of my_int using the variable name Did the value of my int change to 20? Think why, it did or did not change . Using new, allocate dynamic memory to my ipt2 Assign my_iptr to myiptr2. . Dereference my_iptr2 to display the value it is pointing at. Delete both pointers. Complete the requested changes, and then save the file as Lab10B.cpp, making sure to compile and run the program to verify that it produces the correct results. Be sure to review the code to make sure you understand what it is doing. Note that you will submit this file to Canvas
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
