cout<<

worked out for every other pointer data type but... when char is fed it show the pointed address.....(which every one knows)

but i want to see the address stored in the char pointer how to see it..

i was thinking using printf() but ruined out by not knowing what kind of data type is the used to store address...

I am curious in which data type is used to store mem address....
long, int ....

Most of the time when a programmer prints a char*, he wants a string to be printed, not the address. cout assumes that is what you want and to get around it, you need to cast to a different pointer type. void* is a good choice because an object pointer can be cast to void* safely:

#include <iostream>

int main()
{
    char const* p = "string";

    std::cout << p << '\n'
              << (void*)p << '\n';
}

On a side note, this is the same as how printf works with the %p modifier. To be 100% safe, the pointer should be cast to void* because that is the type %p expects:

#include <cstdio>

int main()
{
    char const* p = "string";

    std::printf("%s\n%p\n", p, (void*)p);
}
commented: Nice, so few people get the %p thing right. Though the C++ would have been better with a reinterpret_cast +36
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.