編程就是讓計算機為解決某個問題而使用某種程序設計語言編寫程序代碼,並最終得到相應結果的過程。下面就由本站小編為大家介紹一下C++編程筆試題的文章,歡迎閲讀。
C++編程筆試題篇1
一、請填寫BOOL , float, 指針變量 與“零值”比較的 if 語句。(10分)
提示:這裏“零值”可以是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的值(10分)
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 ) =
C++編程筆試題篇2
簡答題(25分)
1、頭文件中的 ifndef/define/endif 幹什麼用?
2、#include 和 #include “filename.h” 有什麼區別?
3、const 有什麼用途?(請至少説明兩種)
4、在C 程序中調用被 C編譯器編譯後的函數,為什麼要加 extern “C”聲明?
5、請簡述以下兩個for循環的優缺點
// 第一個
for (i=0; i
{
if (condition)
DoSomething;
else
DoOtherthing;
}
// 第二個
if (condition)
{
for (i=0; i
DoSomething;
}
else
{
for (i=0; i
DoOtherthing;
}
優點:
缺點:
優點:
缺點:
C++編程筆試題篇3
有關內存的思考題(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(&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函數會有什麼樣的結果?