Possible Duplicate:
What is the difference between char a[] = “string”; and char *p = “string”;
int main() {
char *p="ayqm";
char c;
c=++*p;
printf("%c",c);
return 0;
}
Its output is a. See http://codepad.org/cbNOPuWt But I feel that the output should be b since c = ++*p.
Anybody can explain the reason for the output?
Sure, it’s undefined behavior. Anything can happen.
You’re attempting to modify a string literal, which is illegal.
If you do, for example
you’ll see the correct output.
The actual type of
pshould beconst char*, in which case you’d get a compiler error.