16,548
社区成员




一,请写出BOOL,float,指针变量与“零值”比较的if语句
1.请写出BOOL flag与“零值”比较的if语句
2.请写出float x 与“零值”比较的if语句
3.请写出char *p与“零值”比较的if语句
二,以下为WINDOWNS下的C++程序,请填写sizeof的值
1.char str[]=”Hello”; sizeof(str)=
2.char *p=str; sizeof(p)=
3.nt n=10; sizeof(n)=
4.void func(char str[100])
{
……
}
则 sizeof(str)=
5.void *p=malloc(100)
则 sizeof(p)=
三,简答题
1.头文件中 ifdef/define/endif主要作用?
2.#include <filename.h> 和#include “filename.h”有什么区别?
3.const有什么作用(至少两条)
4.在C++调用被C编译器编译后的函数,为什么要加extern “C”声明?
5.请简述两个for语句的优缺点
for(i=0;i<N;i++)
{
if(condition)
Dosomething();
else
Dootherthing();
}
优点:
缺点:
if(condition)
{
for(i=0;i<N;i++)
Dosomething();
}
else
{
for(i=0;i<N;i++)
Dootherthing();
}
优点:
缺点:
四,读程序
1.void GetMemory(char *p)
{
p=(char *)malloc(100);
}
void Test(void)
{
char *str=NULL;
GetMemory(str);
strcpy(str,”Hello World”);
printf(str);
}
运行Test()会有什么样的结果
2.char *GetMenory(void)
{
char p[]=”Hello World”;
return p;
}
void Test(void)
{
char *str=NULL;
str= GetMenory();
printf(str);
}
运行Test()会有什么样的结果
3.void GetMemory2(char **p, int num)
{
*p=(char *)malloc(num);
}
void Test(void)
{
char *str=NULL;
GetMenory2(&str,100);
strcpy(str,”Hello”);
printf(str);
}
运行Test()会有什么样的结果
4.void Test(void)
{
char *str=(char *)malloc(num);
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 &abcd); //拷贝构造函数
~String(void); //析构函数
String & operater=(const String &other); //赋值函数
private:
char *m_data; //用于保存字符串
}
请编写String 的上述四个函数