Hi I have a question on pointer to class, please have a look at the snippet below:

Code to instantiate the class through use of pointer

Qt Code:
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Rect
  5. {
  6. public:
  7. int x;
  8. Rect();
  9. };
  10. Rect::Rect()
  11. {
  12. x = 5;
  13. }
  14.  
  15. int main()
  16. {
  17. Rect *re = new Rect;
  18. std::cout << re << std::endl;
  19. std::cout << &re << std::endl;
  20. std::cout << re->x << std::endl;
  21. system("PAUSE");
  22. return 0;
  23. }
  24. */
To copy to clipboard, switch view to plain text mode 

Below is the result from the console:
[HTML]
0x33ffc0
0x23ff70
5[/HTML]

My question, when I try to output re to the console, I assume it will take the address of the object instantiated, and it wrote 0x33ffc0, but when I called for &re, it wrote 0x23ff70. Doesn't &re means I'm displaying the address of the variable pointing to?

So why are they different?
I thought that re contains the address of the object instantiated, and &re should get the address of the object too, as defined in most tutorials on pointer.


doing std::cout << *re will give me an error. I understand from the concept of pointers, that *var will get the value pointed by the pointer. Is my assumption correct that the value is of an object and can't be displayed?

Thanks for reading this, I'm very curious at this, but it's indeed interesting to me!