we can initialise string by a char* as in 1st two steps.but why cant we initialise a char* with a variable defined by keyword string in next two steps?
if we can initialise string type by char* why reverse of that is giving error in 4th step?
std::string is a typedef of a class, and one of its constructors can take a char* argument. This is why you can initialize a std::string variable with a char* value.
char* is a pointer to raw data of type 'char'. 'char' is one of the primitive types, and it knows nothing of std::string. As a result, you cannot assign a std::string to a char*. You can use the c_str() member of std::string to get a const char*, which can be used to assign to a char*.