[Courses] [C] Beginner's Lesson 4B: Errata

KWMelvin kwmelvin at intrex.net
Fri Oct 11 16:07:35 EST 2002


On Fri, Oct 11, 2002 at 06:51:23PM +0100, Peter Clay wrote:
> On Fri, 11 Oct 2002, KWMelvin wrote:
> 
> > The number of elements in {} does not have to match the array size.
> > If too many elements are present, a warning will be issued. If there
> > aren't enough, not all the elements are initialized.  If no length
>                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > is given for the array, C determines the the length from the number
> > of elements in the initialization list.
> > 
> > 	int mem[100] = {0};  /* initialize all elements to zero */
> 
> I'm confused - that comment contradicts your text above.

You know what, now that you point it out, I'm not really sure it works.
According to what is in the text, only the first element memory[0]
would be initialed to zero, and the others would not be initialized
at all.  But for the life of me, I could swear that I've seen that
somewhere before, but I cannot put my hand on it now. 8^D

> 
> > 	char string[50];
> > 	...
> > 	...
> > 	...
> > 	strcpy(string, "Andy");
> > 
> > An array of 50 characters is allocated but the length of the string
> > is 3.
> 
> Er.. 

Er... but the length of the string is 4. 
Thanks!

> > 	Here's a mind bender (legal C code):  o = --o - o--;
> > 
> > 	The problem with the above mind bender is that a programmer can't
> > 	read it -- they have to decode it.
> 
> Nice :) It also has the problem that it may produce different results
> under different compilers.
> 
> -- 
> Peter Clay

Thank you Peter.  

Please keep those cards and letters coming.  We'll get this course
debugged in no time!
--
K




More information about the Courses mailing list