Thread: Need some clearing out on this - (Arrays)

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    39

    Need some clearing out on this - (Arrays)

    Just been reading this http://www.cprogramming.com/tutorial/lesson9.html

    And im a little confused about this...

    To declare a string of 49 letters, you would want to say:

    char string[50];

    This would declare a string with a length of 50 characters. Do not forget that arrays begin at zero, not 1 for the index number.
    Wouldnt it be char String[49]; ?

    When you declare an integer array of 3 you dont say int array[4]; as the indexs would be...

    index[0],[1],[2],[3]

    Rather you would say int array[3]; with the indexs being index[0],[1],[2]

    Maybe this is diffrent in C++ or even strings for that matter...

    Can some one tell me im a idiot and why im one...

  2. #2
    Registered User
    Join Date
    Dec 2005
    Posts
    39
    Never mind reading on I found out its just for strings

    Thanks

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Yep, so called c-style strings are null terminated character arrays. In order for them to behave like strings, they must end in a '\0' character. A good thing might be to forget you ever read about c-style strings and concentrate on C++ strings, which are of type string and they are declared in the header file <string>. They are much easier to use and provide more functionality than c-style strings.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  2. clearing arrays
    By black_sol in forum C++ Programming
    Replies: 5
    Last Post: 08-22-2004, 05:15 PM
  3. clearing char arrays
    By gell10 in forum C++ Programming
    Replies: 7
    Last Post: 06-11-2004, 06:03 PM
  4. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM