Thread: little question about string~

  1. #1
    flashing vampire black's Avatar
    Join Date
    May 2002

    Post little question about string~

    Howdy all~

    this simple trick make me at a loss right now~
    I searched my book which said a 5 elements string like "black" would contains 6 stuffs, and the last one should be '/0', and I was confused with the explainations in page. what's that plz ?

    thanx in advance~
    Never end on learning~

  2. #2
    A "string" is basically an array of chars. Think of a string like [b][l][a][c][k][\0]. The '\0' is a NULL termination for the string. It's an empty "holding space".

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    String constants consist of n+1 characters, n being the number of printed characters in the string and a trailing nul character which determines the end of the string. The string


    is shorthand for


    Five printable characters, plus the nul terminator which says "this is the end of the string". While C++ has a string class which doesn't make use of the nul terminator, C style strings are simply arrays of char. The array may be larger than the string it contains and the rest may contain garbage, so by having a specific character that ends the string, the functions for handling them are drastically simplified.

    My best code is written with the delete key.

  4. #4
    flashing vampire black's Avatar
    Join Date
    May 2002


    so, the size of "black" should be 6, yes ?

    my book tell something about garbage in the chapter follows. maybe I could grasp the exact meaning after reading that.

    thanx, guys~
    Never end on learning~

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  2. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  3. Question...
    By TechWins in forum A Brief History of
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 01:36 PM
  5. Question, question!
    By oskilian in forum A Brief History of
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM