[Courses] re: [C] lesson 7

KWMelvin kwmelvin at intrex.net
Tue Nov 5 14:10:14 EST 2002


On Tue, Nov 05, 2002 at 12:06:51PM -0500, Laura Bowser wrote:
> 
> > Can you assign one array to another? In your code, you do this:
> >     returnchar = "vowel";
> > Does that work?  How about this (see Lesson Four):
> >     strcpy(returnchar, "vowel");
> 
> if the array is a pointer, then yes.  The compiler will "behind the scenes" 
> create the memory structure for this string.  IT'S NOT A GOOD IDEA though!

I'll file this away until we get to pointers in Lesson 12 or so.
Your suggestion that allowing the compiler to do something implicitly
"behind the scenes" IS NOT A GOOD IDEA is well taken.  When we allow
the compiler to do something implicitly, it makes our code less
readable, and less understandable.  The fact that C allows something
to be done, doesn't mean that we, as programmers, HAVE to do it.
In this case, the answer is in Lesson Four (Chapter 4 of _Practical
C Programming 1E_ by Steve Oualline).  It is also quite possible
that not all compilers on all platforms will necessarily do something
"behind the scenes", so our source code may very well be less
"portable" if we rely on the compiler to do things implicitly.
As BEGINNERS, we certainly aren't as familiar with the C Standard
or how it is implemented.  That doesn't mean we can't learn it as
we go along! Thanks for your reply.

Happy Programming!
--
K



More information about the Courses mailing list