#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    421
    Rep Power
    12

    Differences in index arrays


    My book mentions that I can delcare an array like this:

    char line[5] = "Hello";

    Or, like this:

    char line[] = "Hello";

    I understand the compilar will automatically pick out what number should be in the [] but does this take more memory? My book is strong on "Good coding ediket" (or something). Does it use less memory by telling the array the index #er? Or does it not matter?
    Thanks in advance.

    -andy

    P.S. e-d-i-c-k-e-t is spelled wrong cause the forum picked up the word "d-i-c-k" in it. LOL!
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,615
    Rep Power
    4247
    char line[] = "hello"; will pick exactly the number of characters required to store the string (i.e.) 6 characters (5 characters + the trailing null character to delimit the string). It does not take more memory than is required. While you're at it:
    char line[5] = "hello";
    This should really read:
    char line[6] = "hello";

    You're omitting the trailing null character from the array otherwise.

    P.S. I think you mean e-t-i-q-u-e-t-t-e :)
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    421
    Rep Power
    12
    I can't spell..I should be sent back to middle school.
    hmmm...

IMN logo majestic logo threadwatch logo seochat tools logo