當前位置:學識都>好好學習>考研>

文思c++筆試題目

學識都 人氣:2W

簡答題

文思c++筆試題目

1、什麼是純虛函數,什麼是抽象類

2、你對stl瞭解嗎?說下vector的是如何訪問元素的。

3、構造函數能夠設爲私有嗎?

4、類的靜態成員怎麼初始化?const和defined的區別?

5、你對MFC瞭解嗎?WM_SIZE消息在創建對話框的'時候被響應了幾次?

6、你對數據結構瞭解嗎?說說幾種排序算法?

7、postmessage和Sendmessage的區別

8、說說對com的認識。

9、你對qt瞭解不?

程序題

char str[20]=”hello world”;(具體字符串是什麼不知道,類似就是)

char *p = str;

int n = 18;

sizeof(str) = ______; sizeof(p) = ______; sizeof(n) = ______; strlen(str) = ______.

Void saas(char str[100])

{

Cout<

}

2.簡述左 右的優缺點:

For(int k=0; k<10; k++)

{

If(condion == TRUE)

Doaa();

Else

Dobb();

K++;

}

If(condion != false)

{

For(int k=0; k<10; k++)

{

Doaa();

}

}

Else

{

For(int k=0; k<10; k++)

{

Doaa();

}

K++;

}

3.引用傳遞和值傳遞的區別,各在什麼情況下使用。

4. const有什麼用途?(至少說明兩種,舉例)

5. 判斷下面程序的運行結果

void GetMemory(char *p)

{

p = (char *)malloc(100);

}

void Test(void)

{

char *str = NULL;

GetMemory(str);

strcpy(str, ”hello world”);

printf(str);

}

:程序崩潰。

因爲GetMemory 並不能傳遞動態內存,Test 函數中的 str 一直都是 NULL。strcpy(str, ”hello world”);將使程序崩潰。

char *GetMemory(void)

{

char p[] = ”hello world”;

return p;

}

void Test(void)

{

char *str = NULL;

str = GetMemory();

printf(str);

}

可能是亂碼。因爲GetMemory 返回的是指向“棧內存”的指針,該指針的地址不是 NULL,但其原現的內容已經被清除,新內容不可知。

Void GetMemory2(char **p, int num)

{

*p = (char *)malloc(num);

}

void Test(void)

{

char *str = NULL;

GetMemory(&str, 100);

strcpy(str, ”hello”);

printf(str);

}

(1)能夠輸出hello(2)內存泄漏

void Test(void)

{

char *str = (char *) malloc(100

strcpy(str, “hello”);

free(str);

if(str != NULL)

{

strcpy(str, “world”);

printf(str);

}

}

6.輸出結果

class baseq

{

public:

virtual Print()

{

cout<<”base ”<

}

void doprint()

{

Print();

}

};

class ch1:public baseq

{

public:

virtual Print()

{

cout<<”ch1 ”<

}

};

class ch2:public baseq

{

public:

virtual Print()

{

cout<<”ch2 ”<

}

};

void Doprint(baseq *bb)

{

bb->doprint();

}

void main()

{

baseq* b=new baseq;

ch1* c1=new ch1;

ch2* c2=new ch2;

Doprint(b);

Doprint(c1);

Doprint(c2);

delete b;

b=c1;

b-> Print();

b=c2;

b-> Print();

delete c1;

delete c2;

}

7.畫圖簡單說明下進隊和出隊的過程

8.給出一有頭結點的雙向鏈表,要求刪除鏈表的第n個節點,滿足的條件是第n個節點的bvalue > n*n 並且 intx <= n+1.

Struct TNode

{

TNode *preHeader;

TNode *pNextNode;

double bvalue;

int intx;

};