當前位置:學問君>學習教育>考研>

筆試題(循環)

學問君 人氣:3.17W
筆試題(循環)

三、簡答題(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);
}

TAGS:筆試