1. 程式人生 > >strcpy函式為什麼要返回指標?

strcpy函式為什麼要返回指標?

看了好多人的說法,個人認為只有林銳的是正確的。答案:為了實現鏈式表示式。(林銳的答案,沒錯,是這樣的,我同意)
我想增加另外一個原因或者解釋:即strcpy函式能正常執行有如下要求:
Return Value
Each of these functions returns the destination string. No return value is reserved to indicate an error.
The strcpy function copies strSource, including the terminating null character, to the location specified by strDestination. No overflow checking is performed when strings are copied or appended. The behavior of strcpy is undefined if the source and destination strings overlap.

所以,當strDestination和strSource兩者出現交疊時strDestination不能正確返回值,所以此時可以考慮新增char指標來返回原本正確的值。所以strcpy函式一定要返回指標!