c++ question

Grant Robinson santiago at mr-r.net
Fri Sep 22 17:26:34 MDT 2006

On Sep 22, 2006, at 4:35 PM, Richard Scott McNew 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));
> Shouldn't that be:
> print("The address is %p\n", (myarray));
> The variable myarray is a pointer to the beginning of the array.  That
> means that:
> *myarray and myarray[0] are the same.

As you noted in another email, both do work.  The generalized  
principle of getting the address of something works for all pointer  
and non-pointer types (for example, you can take the address of a  
pointer which gives you a pointer to a pointer), but it is worth  
noting that character arrays that are declared as:

char myarray[32];

can be used pretty much anywhere a "char *" is expected, whereas with  
some other types, that is not the case.  My post should have been  
more coherent and thorough by demonstrating that getting the address  
of a character array can be accomplished in the same way as getting  
the address of any other type, be it an int, struct, double, etc.


More information about the PLUG mailing list