Assign reference address to variable

At the beginning of the tutorial at http://www.cplusplus.com/doc/tutorial/pointers/ the first section on reference uses and example of assigning the address to a variable. For example
1
2
3
4
 
andy = 25;
fred = andy;
ted = &andy; 

So that ted will contain some address value like 345342. I wanted to try and replicate that but there isn't any code to try and implement it; Was this more like pseudocode? Here is an attempt I made to try and print out that address value. Commented out you can see variations that didn't work.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main ()
{
	char a = 'x';
	//int myref;		//produces error
	//int& myref = 0;		//not work
	//char myref;		//not work

	unsigned int& myref = &a;

	//myref = &a;		//not work

	cout << "a is " << a << endl;
	cout << "myref is " << myref << endl;
	return 0;
}


This is an example that I found which produces similar output
1
2
3
4
5
6
int main()
 {
   float fl=3.14;
   std::cout << "fl's address=" << (unsigned int) &fl << std::endl;
   return 0;
 }

But I was hoping there was a way to produce what is given in the examples in the tutorials? Do you have to resort to using pointers?
But I was hoping there was a way to produce what is given in the examples in the tutorials? Do you have to resort to using pointers?


Why is that "resorting"? That's exactly what pointers are.
Could you cast it as a int or somthing?

 
cout << hex << ((int) mypointer);
I suppose you could, but it would be pointless and would destory the type system.

Why not just do this:

 
cout << mypointer;
Topic archived. No new replies allowed.