Quote:
why do you magically create a string INSTEAD of a pointer to a single char by using char*?
|
The 'char *' doesn't magically create a string, it really is just a pointer (to a single character).
A string in C++ is not a fundamental type, like it is in some languages. Functions that work with strings use the idea of a null terminated sequence of characters, and the 'char *' argument is just the memory location of the first character in the sequence. The string manipulation functions take the pointer and increment it to step through the characters in the string.
The only strings that you will see in C++ code are the string constants (double quoted sequence of characters), which place the sequence of characters in memory with a null termination character, and have a value which is a pointer to the first character (ie, the start of the string).
It is important to realize that it is not the 'char *s' that creates the space for the string, but the string constant that it is being initialized to. Any pointer ('char *', 'int *', or whatever) that is not initialized will point to an undefined location.
Incidentally, C++ also has a standard template library that provides a dynamically allocated string type, which is a safer way to work with character strings than pointers in high level code.