(*)Pointer value

Hi guys I'm new here and I would like to ask you a question about a little consolle program (very few code just to understand..) and relative output:

1
2
3
4
5
6
7
 int main() {
 int *f;
 f = new int(4);
 cout << *f <<endl; // 1
 cout << f <<endl; // 2
 cout << &f <<endl; // 3
 }

The first cout print the value at the address of f, the third cout print the memory address of f, and the second?

Thank in advance
Giacomino wrote:
The first cout print the value at the address of f, the third cout print the memory address of f, and the second?


The second statement is printing the memory location of whatever the pointer is pointing to. In this case, it's the address of the memory you allocated for your integer using the new operator.
Thanks a lot
Topic archived. No new replies allowed.