Skip to main content
edited title
Link
user529758
user529758

Why is *p++ difference ofdifferent from *p += 1 in void foo(char**p); function?

Source Link
Jack
  • 16.7k
  • 59
  • 172
  • 307

Why is *p++ difference of *p += 1 in void foo(char**p); function?

Consider:

void foo1(char **p) { *p++; }
void foo2(char **p) { *p += 1; }

and

char *s = "abcd";
char *a = s; 
foo1(&a); 
printf("%s", a); //abcd

but if I use foo2() instead of:

char *a = s; 
foo2(&a); 
printf("%s", a); //bcd

Can someone explain it?