Mark McIntyre said:
Pejorative, rigged question and therefore not worthy of an answer.
I see the smiley, but the question was based directly on what you
wrote upthread. It may have been a bit pejorative, but it was not
rigged, at least not deliberately.
Mark:
] >> Remember that in C, = is not the copy operator, its the assignment
] >> operator. For pointer types, this sets the pointers to point to the
] >> same place. It does /not/ copy the contents.
] >[...]
Keith:
] >I don't think I'd phrase it that way.
Mark:
] Yeah, yours is perhaps more correct phrasing, but IMO that would have
] totally confused anyone who thought of "string" as an actual type.
] Since this is a very common newby view, I deliberately chose different
] wording.
It certainly appeared to me that you were assuming certain
misconceptions about what strings are and deliberately not correcting
them for the sake of an explanation of what assignment does. For
example, I found your use of the word "contents" misleading; the
content of a pointer is an address, not the thing it points to.
Saying that "=" is not the copy operator" is not a simplification;
it's just incorrect. It might be a convenient fiction that can help
someone understand that in
char *a = "hello";
char *b;
b = a;
the assignment doesn't copy the string -- but it will inevitably lead
to confusion later on.
There are times when it's appropriate to give not-quite-correct
explanations early on, to be refined later. I don't think this is one
of those cases. The subtle relationship between arrays and pointers
is so central to the way C works that understanding it is an absolute
prerequesite to having a real understanding of the language.
Ignoring your question, I'd say its much less fraught with peril to
start with fundamentals so that by the time the students get to such
complexities as the = operator, they already don't think strings are
PODs.
(POD being Plain Old Data, I presume; I think that's mostly a C++
term, so some here might not be familiar with it.)
I agree with you, but that's not the situation here. The question is
how to explain pointer assignment to someone who *already*
misunderstands C strings. You can give a quick and misleading
explanation that lets the newbie *think* he understands how a
particular program works, or you can give a longer and more correct
explanation, or at least a pointer to one (such as, "read section 6 of
the C FAQ").