| | |
how to print the address stored by char *
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
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 [icode] printf() [icode] 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 ....
Chazing Dreams ;'P
Shhhh.......ZZzzzzzzzzzzzzzzzzzzzz.....
Shhhh.......ZZzzzzzzzzzzzzzzzzzzzz.....
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:
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:
C++ Syntax (Toggle Plain Text)
#include <iostream> int main() { char const* p = "string"; std::cout << p << '\n' << (void*)p << '\n'; }
c Syntax (Toggle Plain Text)
#include <cstdio> int main() { char const* p = "string"; std::printf("%s\n%p\n", p, (void*)p); }
-Tommy (For Great Justice!) Gunn
![]() |
Similar Threads
- Memory Allocation and Deallocation (C)
- Address of a 2D array....... (C++)
- Help to print address of char* (C++)
- Qsort Pointer To Arrays Of Structs (C)
- laern c seriously (C)
Other Threads in the C++ Forum
- Previous Thread: Coding for array pattern matching
- Next Thread: [Help] Game Bot
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





