I don't know how to do the following problem

Complete the Pointer Program

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
Last edited on
Can anyone show me how to do this problem
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 need the solution please
We are not going to do the problem for you.
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?
For instance, is this right?

// ASSIGN the address of variable value1 to pointer variable iPtr
iPtr=&value1;
For instance, is this right?

// ASSIGN the address of variable value1 to pointer variable iPtr
iPtr=&value1;


Try it out: compile full code and look for error. Do not hope we will give full answer. Read the comments and do as it says.
That was ok
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; "

I thought it should be:

*iPtr=&value1

but I can't get it to compile like that
Topic archived. No new replies allowed.