Perhaps:
char * str = "something";
std::cout << &str;
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
>>What about individual characters? Is it possible to get the address of those,
What do you mean? Do you want to get the address of a char variable when it's declared as a straightforward, stand alone variable, when it's an element of a char array, when it's an individual char as part of a string, or when it's an element of a string whose address is stored in a pointer and you want to access it by dereferencing the pointer?
>>or are char values stored in a special way?
Not that I know of.
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
Then again I suppose it's not hard...
const char *c_string = "c-string";
const char& refChar = c_string[0];
std::cout << &refChar << std::endl;
...though I'm not near a C or C++ compiler at the moment so I can't confirm if this will work or not @_@
Or even easier :)
std::cout << reinterpret_cast<void*>( c_string );
edit: that will only work if c_string isn't a const.
edit 2: in order to make that work with c_string as a const, change the cast like this:
std::cout << reinterpret_cast<const void*>( c_string );
William Hemsworth
Posting Virtuoso
1,591 posts since Mar 2008
Reputation Points: 1,429
Solved Threads: 129