On Sep 22, 2006, at 2:08 PM, Dave Smith wrote:

Russel Caldwell wrote:
Sorry, I guess this is a bit off topic but does anybody know if there is a way of obtaining the address where a character array is pointing to in C++?

The pointer value *is* the address. For example:

  char *foo = ....

  printf( "The address is %p\n", foo );

You do not need to use the & operator.

It depends on what you mean by "character array". If you are talking about a variable declared like so:

char myarray[32];

Then to get the address, you would do the following:

print("The address is %p\n", (&myarray));

If you are talking about a variable declared like:

char *myarray = new char[32];

Then the address is stored in 'myarray', and de-referencing 'myarray' will give you the actual contents of the string.

Grant



/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/

Reply via email to