标准库中函数返回值问题

wgzh 2003-08-26 10:52:11
最近关注了一下标准库,发现我们用到的函数很多都有返回值,可是我们却很少用到这些返回值,到底这些值有什么作用呢?
例如: strcpy原型:
char *strcpy(char *strDestination,const char *strSource);
问题:通过strcpy()已经把strSource中的内容拷贝到strDestination中,为何还需要返回char *的返回值呢?

char *strcpy(char *strDestination,const char *strSource)
{
assert( strDestination != NULL && strSource != NULL );
while( *strSource != '\0' )
{
*strDestination = *strSource;
strDestination++;
strSource++;
}
*strDestination = '\0';
return strDestination;
}

...全文
49 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
aflyinghorse 2003-08-26
  • 打赏
  • 举报
回复
同意楼上的
sevecol 2003-08-26
  • 打赏
  • 举报
回复
这个是为了方便你是用函数的执行结果作为其他函数的参数或者表达式中的一项。
liu_feng_fly 2003-08-26
  • 打赏
  • 举报
回复
char sz0[100] = "liu_feng_fly";
char sz1[100];
char sz2[100];
strcpy(sz2,strcpy(sz1,sz0));
这样连接起来用的时候就需要了
bm1408 2003-08-26
  • 打赏
  • 举报
回复
UP!
madasoft 2003-08-26
  • 打赏
  • 举报
回复
读一读林锐博士的书吧。
yinzhaohui 2003-08-26
  • 打赏
  • 举报
回复
有很多的返回值是用来判断这个函数执行成功于否

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧