Hello, I'm a newbie in C/C++ programming and I wonder if you can make me understand the following, I have a small c++ statement, and the result is somehow weird for me:

char[10] arr="torino", *ptr;ptr = arr;cout<<&&ptr;`
and the result gives me the entire string....
PS: This is not related to an assignment.
Thanks in advance

Recommended Answers

All 5 Replies

in the cout statement, there are two missing stars *, one befoe the first & and one before the second.

Is this what you meant?

char[10] arr="torino";
char* ptr;
ptr=arr;
cout << *&*&ptr;

Also, this looks like C++. Next time, post it in the C++ forum :)

I'm glad that you find my typo, that I've also specified in a reply, this is my first post. If you can help me understand, I will be glad. :)

ptr is an object of type char*.
&ptr is a pointer to the object ptr, so an object of type char** (pointer to a char pointer)
*&ptr is the object that &ptr is pointing to, so it's ptr again.
So *&*&ptr is the same as *&ptr.
Do that again, and it's clear that *&*&ptr is the same as ptr

So cout << *&*&ptr; is the same as cout << ptr;

Is that clear?

Yes, thank you very much!!! ~_~

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.