What's the difference between strcpy and stpcpy?

后端 未结 6 964
不知归路
不知归路 2021-01-01 12:57

While reading the man page for strcpy, I discovered the function stpcpy also exists. However, the only difference I could notice in the man page is

6条回答
  •  萌比男神i
    2021-01-01 13:46

    The restrict tells the compiler that s1 and s2 point to different arrays and that there is no overlap in the pointed-to arrays. In some cases this may allow the compiler to perform extra optimizations (i.e., it could possibly copy blocks of multiple characters without having to check for overlap).

    Note also that the return value is different: stpcpy returns a pointer to the \0 that was copied into the destination buffer while strcpy returns a pointer to the beginning of the string (effectively it does a return s1;).

提交回复
热议问题