Thread: c++ array length?

  1. #1
    Registered User
    Join Date
    Nov 2009

    c++ array length?

    Im trying to figure out how many elements are in the array:

    char day[] = "Tuesday";

    and if the array is terminated by a null character. and please explain why

  2. #2
    Registered User
    Join Date
    Apr 2006
    Whenever you write a literal string, it is always implicitly terminated by a null character.

    Tuesday is 7 letters, + \0 makes 8.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Toronto, ON
    cout << sizeof( day ) << endl;
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. warning: excess elements in array initializer
    By redruby147 in forum C Programming
    Replies: 6
    Last Post: 09-30-2009, 06:08 AM
  2. the length of my array is not what I expected
    By luca in forum C Programming
    Replies: 7
    Last Post: 12-05-2006, 02:14 AM
  3. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  4. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 12:01 AM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
Website Security Test