Thread: How come my code works? Seriously. :)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Bit Fiddler
    Join Date
    Sep 2009
    Posts
    79
    Quote Originally Posted by CommonTater View Post
    Ummm... not to be too picky here, but it's not automatically null terminated at all.

    An array of char [8] has 8 elements numbered 0 to 7... element 8 is out of bounds.

    If you put 8 characters in it, it is not null terminated... the null will be a 9th element which will be written out of bounds, launching you into the realm of undefined behavior.
    I know, I know... I don't know where that came from.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Fader_Berg View Post
    I know, I know... I don't know where that came from.
    No worries...

    Normally I'd just raise an eyebrow and let that go by. But in the context of someone trying to understand char arrays, it really did need correction.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code works in Win2K but not XP
    By phantom in forum Windows Programming
    Replies: 7
    Last Post: 04-09-2010, 09:16 PM
  2. Explain this C code in english
    By soadlink in forum C Programming
    Replies: 16
    Last Post: 08-31-2006, 12:48 AM
  3. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Seems like correct code, but results are not right...
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 02-13-2003, 01:33 PM