百度空间 | 百度首页 
 
查看文章
 
C++
2006/10/11 13:35

   #include  <filename.h>    和  #include  “filename.h”  有什么区别?(5 分)
   
    答:对于#include  <filename.h>  ,编译器从标准库路径开始搜索 filename.h
        对于#include  “filename.h”  ,编译器从用户的工作路径开始搜索 filename.h

#############################################################################


在 C++  程序中调用被 C 编译器编译后的函数,为什么要加 extern “C”?  (5 分)

答:C++语言支持函数重载,C 语言不支持函数重载。函数被 C++编译后在库中的名字
    与 C 语言的不同。假设某个函数的原型为:  void foo(int x, int y);
   
    该函数被 C 编译器编译后在库中的名字为_foo,而 C++编译器则会产生像
    _foo_int_int 之类的名字。
   
    C++提供了 C 连接交换指定符号 extern“C”来解决名字匹配问题。

#############################################################################
五、编写 strcpy 函数(10 分)
    已知 strcpy 函数的原型是
    char *strcpy(char *strDest, const char *strSrc);
    其中 strDest 是目的字符串,strSrc 是源字符串。
  
   (1)不调用 C++/C 的字符串库函数,请编写函数 strcpy
 
 char *strcpy(char *strDest, const char *strSrc);
 {
      assert((strDest!=NULL) && (strSrc !=NULL));  // 2分
      char *address = strDest;      // 2分
      while( (*strDest++ = * strSrc++) != ‘\0’ )    // 2分
         NULL ; 
      return address ;        // 2分
 }
 
    (2)strcpy 能把 strSrc 的内容复制到 strDest,为什么还要 char *  类型的返回值?
     答:为了实现链式表达式。        // 2 分
      例如  int length = strlen( strcpy( strDest, “hello world”) );


类别:编程学习 | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu