On Sep 23, 2006, at 3:48 PM, Dave Smith wrote:


At least we agree that the & operator is not needed to print the address of a character array, which was the original poster's question.

I hope this has been enlightening for the original poster, since the original question betrayed a serious lack of knowledge regarding arrays in C/C++.

Lessons to take home, for anyone still reading:

Arrays and pointers are not equivalent, though they are interchangeable in some situations.

C strings are almost purely a matter of convention; char * is not a string and is not an array, it is an index into C's Single Big Array, at which particular index the data should be considered here to be a char, though we can't know in general if it was indeed meant to be a char.

The & operator returns the address associated with the storage location of a variable. In the case of an array variable, that's the first location in the array. In the case of a pointer variable, that's the location of the word that holds the pointer. It is legal and quite reasonable to use to find the address of an array variable, though more verbose than other methods.

C++ introduces additional complication due to overloading of functions and operators, so passing values of different types to a possibly overloaded function will not necessarily reveal differences in those values if you are expecting them to be treated the same.

In addition, it is my opinion that we ought to, as programmers, eschew usage of both C and C++ whenever possible in favor of languages that are more helpful to us and less prone to error. There are quite a few available, many of which have implementations capable of similar efficiency to modern C compilers, so finding a suitable one is left as an exercise to the reader. You are, of course, free to disagree with my opinion on the matter.

                --Levi

/*
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