Complete the following program:
Include the comments below with your code and use the variable names provided. Your output must match the sample output, except for the addresses which will be different. Why will the addresses be different???
// Lab4_ExerA.cpp
// CSC134 - Lab 4 - Exercise A
// Name:
//
// State in words what this program is doing
#include <iostream>
using namespace std;
int main()
{
int value1 = 2000;
int value2;
// DECLARE the variable iPtr to be a pointer to an
// object of type int
// ASSIGN the address of variable value1 to pointer
// variable iPtr
// PRINT the value of the object pointed to by iPtr
// ASSIGN the value of the object pointed to by iPtr
// to value2
// PRINT the value of value2
// PRINT the address of value1
// Print the address stored in iPtr
}
Sample Output:
Value of object pointed to by iPtr is 2000
Value of value2 is 2000
Address of value1 is 0034FA90
Address stored in iPtr is 0034FA90
I assume you want to learn how pointers work (and not just turn in the completed assignment), so let's deconstruct the problem. You can start by declaring iPtr.
I have completed this exercise and I want to make sure that I didn't do it 'backwards'. So the answers aren't public, could I post somewhere privately?
I have completed the assignment and it compiles correctly, and the output seems to match the exercise's. That's why I want to know if my assignment statement is correct "// ASSIGN the address of variable value1 to pointer variable iPtr: iPtr=&value1; "