Array question

This is a discussion on Array question within the C++ Programming forums, part of the General Programming Boards category; hey guys just wondering if when you put a word in a character array is this still classed as dealing ...

  1. #1
    182
    182 is offline
    Registered User
    Join Date
    Oct 2005
    Posts
    133

    Array question

    hey guys just wondering if when you put a word in a character array is this still classed as dealing with a character string?

    thanks.

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Could you post an example? What do you mean by word? (this or this)
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    182
    182 is offline
    Registered User
    Join Date
    Oct 2005
    Posts
    133
    Quote Originally Posted by JaWiB
    Could you post an example? What do you mean by word? (this or this)
    Hi sorry for not being clear by word i mean say i had a char array which was char example [100];
    and it contained "hello" would hello be classed as a string even though its in a char array?

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,062
    It's either classified as a null-terminating string, or probably the most proper, c-string.

    In many cases with c-strings, saying string may also be acceptable, since what you're thinking of as a string is more properly classified as a std::string or a string object.
    Sent from my iPadŽ

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    char word[] = "hello";

    "hello" is called a string literal.

    The compiler will determine the length of "hello" and declare space for each char in "hello" plus a null terminating char and stores the same value of each of the chars of "hello" in word in the same order they occur in "hello" in addition to a terminating null character. You can now modify the contents of word as desired. word is called a c-style string or null terminated char array.

    Compare that with this:

    char * word = "hello";

    Now "hello" is still a string literal, but the address of the h in "hello" is assigned to word and the values of the chars in word can not be changed although the address stored in word can be changed. word is still considered to be a string, though it's not a null terminated char array.
    You're only born perfect.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic Mutli dimensional Array question.
    By fatdunky in forum C Programming
    Replies: 6
    Last Post: 02-22-2006, 06:07 PM
  2. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. array question?
    By correlcj in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2002, 05:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21