c++ question

Dave Smith dave at thesmithfam.org
Sat Sep 23 13:49:20 MDT 2006


Grant Robinson wrote:
> 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.
>

Wrong. In both cases (char* and char[]), the variable itself stores the 
address. You do not need the & operator in either case.

In fact, using the & operator is incorrect, because it will give you the 
address of the variable that was already holding the address of the 
character array, instead of the address of the character array.

--Dave



More information about the PLUG mailing list