| | |
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 array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





