笔试题循环

时间:2021-04-24 13:29:29 笔试题目 我要投稿

笔试题(循环)

三、简答题(25分)
1、头文件中的 ifndef/define/endif 干什么用?
2、#include %26lt;filename.h%26gt; 和
#include "filename.h" 有什么区别?
3、const 有什么用途?(请至少说明两种)
4、在C++ 程序中调用被 C编译器编译后的函数,
为什么要加 extern "C"声明?
5、请简述以下两个for循环的'优缺点
// 第一个for (i=0; i%26lt;N; i++)
{if (condition)
DoSomething();
else
DoOtherthing();}
优点:缺点:
// 第二个if (condition)
{for (i=0; i%26lt;N; i++)
DoSomething();}
else{
for (i=0; i%26lt;N; i++) DoOtherthing();}
优点:缺点:
四、有关内存的思考题(20分)
void GetMemory(char *p)
{
p = (char *)malloc(100);
}
void Test(void)
{
char *str = NULL;GetMemory(str);
strcpy(str, "hello world");
printf(str);
}请问运行Test函数会有什么样的结果?答:
char *GetMemory(void)
{
char p[] = "hello world";
return p;
}
void Test(void)
{
char *str = NULL;
str = GetMemory();
printf(str);
}
请问运行Test函数会有什么样的结果?答:
Void GetMemory2(char **p, int num)
{
*p = (char *)malloc(num);
}
void Test(void)
{
char *str = NULL;
GetMemory(%26str, 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函数(10分)
已知strcpy函数的原型是
char *strcpy(char *strDest, const char *strSrc);
其中strDest是目的字符串,strSrc是源字符串。
(1)不调用C++/C的字符串库函数,请编写函数 strcpy
(2)strcpy能把strSrc的内容复制到strDest,为什么还要char * 类型的返回值?
 

笔试题(循环)

【笔试题(循环)】相关文章:

华为2017笔试题08-16

360笔试题目10-20

华为2017笔试试题08-10

桂林银行笔试题笔经10-21

QMS2007笔试审核知识模拟试题05-02

SAT循环阅读法08-17

眼线笔类型-如何挑选眼线笔11-09

循环经济发展政策11-15

循环经济立法之定位10-31

马克笔有哪些分类-马克笔的分类11-03