case1:char* a="cplus";
cout<<*a; //outputs c
cout<<a[0]; // outputs c
case2:char e[]="cplus";
cout<<*e; // outputs c
cout<<e[0]; //outouts c
case3: string s="cplus";
cout<<*e; // giving an error
cout<<e[0]; // outputs c
DOUBT: all the cases above define a string. As we know in strings a[0] is equivalent to *a as seen in case 1,2. but why case 3 is showing error when we type *e.
Is there any difference between string defined by a pointer or array and the string that is defined by keyword "string"? if so please tell those differences and why there should be such differences exists while we define string in different ways?
Assuming you meant to type *s and s[0] in case 3, the following is my explanation:
Case 1 creates a pointer, often to a read-only location in memory, meaning that if you tried to modify the string, you may end up making the OS throw an error. It is safe to change the address that the pointer points to, but not the data.
Case 2 creates a string as a character array. This is a constant pointer to a modifiable section of memory. That is, you can change the data, but you can't change the address that the pointer points to.
Case 3 creates an instance of a std::string, where you can modify the data, though technically it just creates a new string and self-assigns the new string to the current one. Of course, you can't change the pointer because std::string isn't a pointer. I suppose the pointer dereference operator could have been overloaded, but it is not really used that often when you have a string. After all, you usually work with the whole string when you refer to individual elements (often via loops). For that reason, I don't think it is necessary to overload it to be able to do *ptr when ptr[0] works just as well.
Of course, if you didn't mean *s in case 3, then I would guess that you simply didn't create the 'e' variable in that program. :P