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.
Printable View
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.
Hi sorry for not being clear by word i mean say i had a char array which was char example [100];Quote:
Originally Posted by JaWiB
and it contained "hello" would hello be classed as a string even though its in a char array?
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.
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.