char *p="orkut" vs const char *p="orkut"
whats the difference btwn these two…
EDIT
from bjarne stroustrup,3rd edition page 90
void f()
{
char* p="plato";
p[4]='e' // error: assign to const;result is undefined
}
this kind of error cannont be general b caught until run time and implementations differ in their enforcement of this rule
Same with const char *p=”plato”
Thats why iam asking the diffrence… Whats the significance of const here..
The
const char*variant is correct.You should not change memory that comes from a string literal (referred to as static storage usually). It is read only memory.
The difference is that the
char*variant will allow you to write the syntax to change the data that it points to by dereferencing it. What it actually does though is undefined.I would rather have option 2 happen to me.