[OCLUG-devel] arrays

James Colannino james at colannino.org
Sun May 29 04:31:13 PDT 2005


Hey everyone.  I have another C question, this time regarding arrays. 
I'm wondering what would happen if you did the following:

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);

I know this is NEVER something you should do, but so far, out of
curiosity (and buggy code :-P), I've gotten away with it every time I've
tried, and I'm curious what the possible ill effects are.  Thanks in
advance.

James
-- 
My blog: http://www.crazydrclaw.com/
My homepage: http://james.colannino.org/

"A well regulated militia being necessary to the security of a free
state, THE RIGHT of the people to keep and bear arms SHALL NOT BE
INFRINGED." --United States Constitution, Second Ammendment


More information about the OCLUG-devel mailing list