Help with pointers!

Hi! I'm a begginer and I wanted apply what I've read from tutorials. But something isn't working as I expect.Given an character, I create a pointer to it, and print the character and the value of the pointer (the address of the character). But the last part prints exactly the same as the first (the character) instead of its address.

Here's my code, so you can see what I mean:
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

using namespace std;
int main()
{char j='W';
char *p;
p=&j;

cout<<p<<endl;/*Address of j, value of p*/
cout<<*p<<endl;/*Value of j, pointed at by p*/

}


And the output is
W
W



So, there must be something wrong. Could you help me?
You haven't read up on what cout does.

if you pass cout a char*, it will dereference that pointer and output the char it is pointing at, and all following chars until it gets to a zero value. So when you do this:
cout<<p<<endl;
cout dereferences the pointer, and outputs what it points at - W.

When you pass cout a char, it output that char. So when you do this, which is passing a char:
cout<<*p
cout outputs that char - W.
Then what can I do to print the value of p, j's address?
About half-way down the page on this thread:
http://www.cplusplus.com/forum/beginner/73491/
Thanks!, I solved it!
Topic archived. No new replies allowed.