面试C++试题[3]

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 x1001 的 blog

char *strcpy_x(char *strdest, const char *strsrc)

{

    if((strdest==null) || (strsrc ==null))

       return null;       // 2

    if(strdest==strsrc)//add by xie

       return strdest;   

    char *address = strdest;                                     // 2

    while( (*strdest++ = * strsrc++) != '\0' )              // 2

       ;

   return address ;                                          // 2

}

我当时这样写的理由如下:

a.              没必要为一个strcpy函数中的参数有null断言大错涌出,返回null值也是一个好见识

本文关键:C++,林锐,面试试题
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top