How does this C copy function exit its loop?

后端 未结 3 1554
心在旅途
心在旅途 2021-01-21 03:14
void copy (char *source, char *dest) {
    while (*dest++ = *source++);
}

The char that is represented by *source is copied to the field <

3条回答
  •  深忆病人
    2021-01-21 03:40

    The 'result' of an assignment is the right-hand value. So x=1; actually returns a value; in this case, '1'.

    Your code copies characters until it encountered the terminating 0 at the end of the source string.

提交回复
热议问题