-1
char *_strcat(char *dest, char *src)
{
    char *temp = dest;

    while (*dest)
        dest++;

    while (*src)
        *dest++ = *src++; ====> this line

    *dest = '\0';
    return (temp);
}

I don't understand the line of code I specified above; does it update both the value and address of dest, or does it just update the value.and also what is the main logic here.I am lost!

wohlstad
  • 12,661
  • 10
  • 26
  • 39

1 Answers1

0

The precedence of the ++ operator is higher than the * operator, but as ++ — in an expression — uses the old value of the operand, the part:

*dest++ = *src++;

first dereferences the src pointer, initializing the memory address pointed to by dest, then increments both the pointers by 1 to point to the next character.

In a loop, this copies the memory contents of src to dest.

It's the same as doing;

*dest = *str;
dest++;
str++;

Or

*dest = *src;
dest += 1;
src += 1;
Harith
  • 4,663
  • 1
  • 5
  • 20