Here is what my book says:
char *p="Hello"; //pointer is variable, string is constant *p='M'; // error p="bye"; // works Well, in C my second line does not give me any error, Neither in C++.
I am using Turbo C++ on windows 7. Now is the above thing true if i try in gcc or something else.
Also on the similar lines if the above code is correctly interpreted by the book,
#include<iostream.h> void display(char*); void display(const char*); void main() { char* ch1="hello"; const char *ch2="bye"; display(ch1); display(ch2); } void display(char* p) { cout << p << endl; } void display(const char* p) { cout << p << endl; } Now is my book considering char* and const char* the same because if it is then the above code shall not work, since arguments will be the same?
(Though i get the output Hello bye on turbo +windows.)
Which one is correct?
const char *to refer to them.const char*? Does it automatically typecast it or remains as such?const char *tochar *". No matter what you have, writing to the data is always undefined behaviour.