void mystrcat(char* dest,char* src)
{
while(*dest) dest++;
while(*dest++=*src++);
return;
}
The above block of code is an user-defined function to copy the contents of a string to the end of another string.
Here, we walk through the destination string until it hits the null character '\0'
. The 2nd while loop is supposedly used to copy the contents the source string to the end of destination string.
I have read that an expression such as, *ptr++
is evaluated as *(ptr++)
according to the precedence table of operators in C.
If that is the case shouldn't the expression: *dest++=*src++
be evaluated as
*(dest++)=*(src++)
?
Wouldn't that cause dest to first point to the next location in the memory and updating its value rather than, updating '\0'
with a character from the source string? Similarly, won't it cause src
to miss the 1st character of the source string?
However, the function seems to be successful in copying the contents of the source string to the end of the destination string.