i want to out put an elements address to the console but im having trouble with it.
cout << &text[0] << endl;
it seems to is output its vaule, what am i doing wrong here?
thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to convert to
void *for the printing with iostreams, and you need a safe address-of operator that doesn’t get confused by overloaded&-operators. In other words:You need
<memory>and<iostream>, as well as a recent compiler.Update: Note that this code gives you the static address of the operand. If you want to pass a base reference of a polymorphic object, you should use
dynamic_cast<void*>(x)instead, but this works only for polymorphic objects (i.e. those with virtual functions), and it gives you the address of the actual, dynamic object.