Sunday, July 12, 2009

C++ characters and strings?

Whats the difference between a String and a Character?

C++ characters and strings?
A character is a single "character" whereas a string is many "characters".





A string is an array of characters.
Reply:a chararacter (a char actually) is a primative that represents a single character. (like a 'M', 'm' , ' ', ')' or even a new line ('\n')). A string is an object that is part of the standard C++ library. You can think of it as a collection of characters that go together in a specific order. In reality strings are a very special type of object with lots of overloading, but you don't need to know all this.





"asdasd" is a string.





Note: I am reffering to C++ strings, not C strings. (They are VERY different) in C++ a string is NOT just an array of characters. in C a string is an array of characters that is ended by a null character ('\0').


No comments:

Post a Comment