Pointer & Address Help

So, my professor has asked us to declare a pointer capable of pointing at an int. Then continue to make the pointer point at a new integer. Then continue to print out the address of that new integer and the address of that pointer. So I`ve never written pointer but I have attempted. So my question is this right?
1
2
3
4
5
6
7
8
9
#include <iostream>

using namespace std;

int main(){
 int*newint; // declaring a pointer that will point at an int and point at a new 
             // integer
	cout<<&newint<<endl; //finding the new integer address?
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <iomanip>

using namespace std;

int main() 
{
  int num1 = 1, num2 = 2;
  int *ip = &num1;

  cout << "Value of *ip: " << *ip << "\n";
  cout << "Address of ip pointing : " << hex << ip << "\n";
  ip = &num2;
  cout << "After pointing ip to num2" << "\n";
  cout << "Value of *ip: " << *ip << "\n";
  cout << "Address of ip pointing: " << hex << ip << "\n";
}
Well I guess that answers my question in all ways.
Topic archived. No new replies allowed.