[Courses] [C] Beginner's Lesson 4B: Arrays, Qualifiers, and Reading Numbers

Peter Clay pete at flatline.org.uk
Fri Oct 11 18:51:23 EST 2002


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.

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

Er.. 

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

Pete
-- 
Peter Clay                                         | Campaign for   _  _| .__
                                                   | Digital       /  / | |
                                                   | Rights!       \_ \_| |
                                                   | http://uk.eurorights.org




More information about the Courses mailing list