Leo Messi
Leo Messi

Reputation: 822

strcpy : Implementation method

I was going through a possible implementation method for library function strcpy. It is :

void strcpy(char *src, char *dest)
{
while (*dest++ = *src++)
            ;
}

How can this possibly work without check of '\0' ??

Upvotes: 3

Views: 4403

Answers (1)

jason
jason

Reputation: 241583

The result of *dest++ = *src++ is the value of *src before the increment of src. If this value is \0, the loop terminates.

Upvotes: 6

Related Questions