If I have a pointer that points to a string variable array of chars
, is there a difference between typing:
char *name = \"name\";
Yes, char*
is the pointer to an array of character, which is a string. string *
is the pointer to an array of std::string
(which is very rarely used).
string *name = "name";
"name" is a const char*
, and it would never been converted to a std::string*
. This will results compile error.
The valid declaration:
string name = "name";
or
const char* name = "name"; // char* name = "name" is valid, but deprecated