const char or char* difference


hii.
can I have diffirence between const char or char *.When I compile following
program than got following output.

int main()
{

char *p ="abhishek"; // compiling error

const char *p ="abhishek"; // No compilation error

}

Any reason behind this.
"abhishek" is a constant string, so you have to address the pointer that points to it as constant.
yes I got it but can it be issue for compilation error?. if I declare const char than I will not get
any compiler error. or if i do not declare than i will encounter will compiler error.

I had understanding that we can not assign new value in the above case (i.e p[2]='s' will compiler
error) but does it also allow char *p?

You're confusing your consts.
http://www.cplusplus.com/forum/beginner/10602/
Sorry but it was explaning about const char* or char *const pointer.

But my question is:

char *s ="Marry"--> compiler error

const char* temp ="jonh" --> excepted by complier

what is the reason behind this?
PiMaster already said that string literals are constant character arrays.
When taking the address of a constant character, you'll get a pointer to a constant character, which you can't assign to a pointer to a non-const character.
opps I got it.. my applogizes for missing this thing.. thx a lot for your reply
Topic archived. No new replies allowed.