C++笔试题目(林锐的 高质量程序设计指南--C++/C )

 一、请填写   BOOL,float,指针变量   与“零值”比较的   if   语句。  
   
  提示:这里“零值”可以是   0,0,0,FALSE   或者“空指针”。例如   int   变量   n   与“零值”比较的   if   语句为:  
  if(n==0)  
  if(n!=0)  
  以此类推。  
   
  请写出   BOOL   flag   与“零值”比较的   if   语句:_______________  
  请写出   float   x   与“零值”表较的   if   语句:     _______________  
  请写出   char   *p   与“零值”比较的   if   语句:     _______________  
   
   
  二、以下为   Windows   NT   下的   32   位   C++   程序,请计算   sizeof   的值  
   
  char   str[]="Hello"  
  char   *p=str  
  int   n=10;    
   
  请计算:  
  sizeof(str)=_____  
  sizeof(   p   )=_____  
  sizeof(   n   )=_____  
   
  void   func   (char   str[100])   请计算   sizeof(str)=_____  
  void   *p=malloc(100)     请计算   sizeof(   p   )=_____  
   
   
  三、简答题  
   
  1、头文件的   ifndef   /   define   /   endif   干什么用?  
   
  2、#include<filename.h>   和   #include"filename.h"   有什么区别?  
   
  3、const   有什么用途?(请至少说明两种)  
   
  4、在   C++   程序中调用被   C   编译器编译后的函数,为什么要加   extern   “C”申明?  
   
   
  四、有关内存的思考题  
   
  void   GetMemory(char   *p)  
  {  
          p=(char   *)malloc(100);  
  }  
  void   Test(void)  
  {  
          char   *str=null;  
          GetMemory(str);  
          strcpy(str,"hello   world");    
          printf(str);  
  }  
  请问运行   Test   函数会有什么结果?   答:__________________________  
   
  void   GetMemory(char   **p,int   num)  
  {  
          *p=(char   *)malloc(num);  
  }  
  void   Test(void)  
  {  
          char   *str=NULL;  
          GetMemory(&str,100);strcpy(str,"hello")  
          printf(str);  
  }  
  请问运行   Test   函数会有什么样的结果?答:__________________________  
   
  void   Test(void)  
  {  
          char   *str=(char   *)malloc(100);  
          strcpy(str,"hello");  
          free(str);  
          if(str   !=   NULL)  
          {  
                  strcpy(str,"world");  
                  printf(str);      
          }  
  }    
  请问运行   Test   函数会有什么样的结果?答:__________________________  
   
   
  五、编写   strcpy   函数  
   
  已知   strcpy   函数的原形是:char   *strcpy(char   *strDest,const   char   *strSrc);  
  其中   strDest   是目的字符串,strSrc   是源字符串。  
   
  (1)不调用   C++/C   的字符串库函数,请编写汉书   strcpy  
   
   
   
   
  (2)strcpy   能把   strSrc   的内容复制到   strDest   ,为什么还要   char   *   类型的返回值?  
   
   
  六、编写类   String   的构造函数、析构函数和赋值函数  
   
  已知类   String     的原形为:  
  class   String  
  {  
          public:  
                        string(const   char   *str=NULL);   //普通构造函数  
        string(const   String   &other);     //拷贝构造函数  
        ~String(void);   //析构函数  
        String   &   operate=(const   String   &other);   //赋值函数  
          pravite:  
                        char   *m_data;   //用于保存字符串  
  };  
  请编写   String   的上述   4   个函数。  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值