[OCLUG-devel] arrays

Morgan Simpson msimpson at braysimpson.com
Sun May 29 08:37:54 PDT 2005


On May 29, 2005, at 4:31 AM, James Colannino wrote:

> char array[5];
>
> for (i = 0; i <= 10; ++i)
>     array[i] = 'a';
>
> array[11] = '\0';
>
> /* notice that I've indexed through 7 more than I should have */
>
> printf ("%s\n", array);

James, this is an open invitation for a segmentation fault.

Just out of curiosity, do all 10 characters print in your test case?

Regards,
Morgan Simpson
Bray, Simpson & Associates, Inc.



More information about the OCLUG-devel mailing list