I was confused by the expression *d++=*s++
. How to undertand it.
int main()
{
char s[20]="hello,world";
char d[20];
char *src=s;
char *des=d;
while(*src) *des++=*src++;
return 0;
}
I was confused by the expression *d++=*s++
. How to undertand it.
int main()
{
char s[20]="hello,world";
char d[20];
char *src=s;
char *des=d;
while(*src) *des++=*src++;
return 0;
}
It has the same behavior as:
*dest = *src;
dest++;
src++;
That is copy the character pointed at by src
to the character pointed at by dest
. Then move each pointer to the next character element.