c++ question

Levi Pearson levi at cold.org
Sat Sep 23 15:14:31 MDT 2006

On Sep 23, 2006, at 1:49 PM, Dave Smith wrote:

> 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.

No, you are wrong, at least partially.  Both a char * and char[]  
variable will evaluate to an address, but in the case of char[] that  
address is both the address of the first element /and/ the address of  
the variable itself.  With a char *, the address it is pointing to is  
not the same as its own address, so the & operator acts differently  
on char * than char[].

This is an error that is easy for experienced C programmers to make,  
though, since real array variables are so rare and act so much like  
pointer variables.  But arrays really are different from pointers,  
and this is one of the few ways in which they are different.


More information about the PLUG mailing list