c++/c程序員基本編程技能筆試
本試題僅用于考查c++/c程序員的基本編程技能。 內(nèi)容限于c++/c常用語法,不涉及數(shù)據(jù)結構、算法以及深奧的語法。 考試成績能反映出考生的編程質量以及對c++/c的理解程度, 但不能反映考生的智力和軟件開發(fā)能力。 筆試時間90分鐘。請考生認真答題,切勿輕視。 一、請?zhí)顚慴ool , 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 ) = 三、簡答題(25分) 1、頭文件中的 ifndef/define/endif 干什么用? 2、#include 和 #include "filename.h" 有什么區(qū)別? 3、const 有什么用途?(請至少說明兩種) 4、在c++ 程序中調用被 c編譯器編譯后的函數(shù), 為什么要加 extern "c"聲明? 5、請簡述以下兩個for循環(huán)的優(yōu)缺點 // 第一個for (i=0; i {if (condition) dosomething(); else dootherthing();} 優(yōu)點:缺點: // 第二個if (condition) {for (i=0; i dosomething();} else{ for (i=0; i 優(yōu)點:缺點: 四、有關內(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); }請問運行test函數(shù)會有什么樣的結果?答: char *getmemory(void) { char p[] = "hello world"; return p; } void test(void) { char *str = null; str = getmemory(); printf(str); } 請問運行test函數(shù)會有什么樣的結果?答: 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函數(shù)會有什么樣的結果?答: void test(void) { char *str = (char *) malloc(100); strcpy(str, "hello"); free(str); if(str != null) { strcpy(str, "world"); printf(str); } } 請問運行test函數(shù)會有什么樣的結果?答: 五、編寫strcpy函數(shù)(10分) 已知strcpy函數(shù)的原型是 char *strcpy(char *strdest, const char *strsrc); 其中strdest是目的'字符串,strsrc是源字符串。 (1)不調用c++/c的字符串庫函數(shù),請編寫函數(shù) strcpy (2)strcpy能把strsrc的內(nèi)容復制到strdest,為什么還要char * 類型的返回值? 六、編寫類string的構造函數(shù)、析構函數(shù)和賦值函數(shù)(25分) 已知類string的原型為: class string { public: string(const char *str = null); // 普通構造函數(shù) string(const string other); // 拷貝構造函數(shù) ~ string(void); // 析構函數(shù) string operate =(const string &other); // 賦值函數(shù) private: char *m_data; // 用于保存字符串 }; 請編寫string的上述4個函數(shù)。 |
【c++/c程序員基本編程技能筆試】相關文章:
2017年c語言面試筆試題03-19
華為程序員面試筆試試卷03-11
java程序員面試筆試試題03-11
筆試的面試技巧11-21
中興筆試面試經(jīng)驗03-12
華為筆試網(wǎng)絡題03-11
面試筆試題03-22
保利面試筆試03-22
2017程序員就業(yè)城市03-08