- 相關(guān)推薦
筆試題(循環(huán))
三、簡(jiǎn)答題(25分)
1、頭文件中的 ifndef/define/endif 干什么用?
2、#include %26<filename.h%26> 和
#include "filename.h" 有什么區(qū)別?
3、const 有什么用途?(請(qǐng)至少說(shuō)明兩種)
4、在C++ 程序中調(diào)用被 C編譯器編譯后的函數(shù),
為什么要加 extern "C"聲明?
5、請(qǐng)簡(jiǎn)述以下兩個(gè)for循環(huán)的優(yōu)缺點(diǎn)
// 第一個(gè)for (i=0; i%26<N; i++)
{if (condition)
DoSomething();
else
DoOtherthing();}
優(yōu)點(diǎn):缺點(diǎn):
// 第二個(gè)if (condition)
{for (i=0; i%26<N; i++)
DoSomething();}
else{
for (i=0; i%26<N; i++) DoOtherthing();}
優(yōu)點(diǎn):缺點(diǎn):
四、有關(guān)內(nèi)存的思考題(20分)
void GetMemory(char *p)
{
p = (char *)malloc(100);
}
void Test(void)
{
char *str = NULL;GetMemory(str);
strcpy(str, "hello world");
printf(str);
}請(qǐng)問(wèn)運(yùn)行Test函數(shù)會(huì)有什么樣的結(jié)果?答:
char *GetMemory(void)
{
char p[] = "hello world";
return p;
}
void Test(void)
{
char *str = NULL;
str = GetMemory();
printf(str);
}
請(qǐng)問(wèn)運(yùn)行Test函數(shù)會(huì)有什么樣的結(jié)果?答:
Void GetMemory2(char **p, int num)
{
*p = (char *)malloc(num);
}
void Test(void)
{
char *str = NULL;
GetMemory(%26str, 100);
strcpy(str, "hello");
printf(str);
}
請(qǐng)問(wèn)運(yùn)行Test函數(shù)會(huì)有什么樣的結(jié)果?答:
void Test(void)
{
char *str = (char *) malloc(100);
strcpy(str, "hello");
free(str);
if(str != NULL)
{
strcpy(str, "world");
printf(str);
}
}
請(qǐng)問(wèn)運(yùn)行Test函數(shù)會(huì)有什么樣的結(jié)果?答:
五、編寫(xiě)strcpy函數(shù)(10分)
已知strcpy函數(shù)的原型是
char *strcpy(char *strDest, const char *strSrc);
其中strDest是目的字符串,strSrc是源字符串。
(1)不調(diào)用C++/C的字符串庫(kù)函數(shù),請(qǐng)編寫(xiě)函數(shù) strcpy
(2)strcpy能把strSrc的內(nèi)容復(fù)制到strDest,為什么還要char * 類(lèi)型的返回值?
【筆試題循環(huán)】相關(guān)文章:
360筆試題01-20
12580筆試題01-20
筆試-CRI 2010筆試題01-19
《水循環(huán)》教案02-21
《水循環(huán)》教案07-03
循環(huán)小數(shù)教案04-04
《水循環(huán)》教學(xué)反思08-04
循環(huán)小數(shù)教案03-26
《循環(huán)小數(shù)》教案03-03