華為SH面試題

2021-05-27 09:56:25 字數 4909 閱讀 9052

c++/mfc 試題

一.填空題 (26 分 )

1 . win32 平台下, sizeof(short) = __2__ , sizeof(int) = __4__ , sizeof(long) = __4__ 。 (3 分 )

2 .請給出如下程式的結果 (2 分 )

int a = 3;

int b = a << 3;

a = __3__ , b = __24__ 。

3 .請 給出如下程式的結果 (2 分 )

int aaa = 0x01;

htonl(aaa) = _16777216___ 。 //這題執行顯示的是16777216,我覺得可能是隨機值

4 .請給出如下程式的結果 (2 分 )

#define max_num 100+200

int ntemp = max_num*10;

則 temp = __2100__ 。

5 .請給出如下程式的結果 (3 分 )

char sztemp[1000] = "";

int nlen1 = sizeof(sztemp);

int nlen2 = strlen(sztemp);

strcpy(sztemp, "abc");

int nlen3 = sizeof(sztemp);

int nlen4 = strlen(sztemp);

int ntemp[100];

int *ptemp = ntemp;

int nlen5 = sizeof(ptemp);

char szresult[200] = "";

sprintf(szresult, "%d,%d,%d,%d,%02d.", nlen1, nlen2, nlen3, nlen4, nlen5);

則 szresult = ____ 。

__7 .記憶體是程序範圍 or 執行緒範圍; ____

cpu 排程時,針對程序 or 執行緒; ____

函式呼叫堆疊,針對程序 or 執行緒。 ____(3 分 )

8 .呼叫函式 bbb 後,輸出是什麼 (4 分 )

void ccc(int x)     

char sztemp[10] = "";

x = 2;

sprintf(sztemp, "%d,", x);

afxdump << sztemp;

if(x = 3)

int x = 4;

sprintf(sztemp, "%d,", x);

afxdump << sztemp;

sprintf(sztemp, "%d,", x);

afxdump << sztemp;

void bbb()

char sztemp[10] = "";

int x = 7;

ccc(x);

sprintf(sztemp, "%d,", x);

afxdump << sztemp;

二.改錯題 ( 總共 15 分 , 每題 5 分 ) 。

1 .下面**有何錯誤

void func1()

int *pa = null;

func2(pa);

delete pa;

void func2(int *pb)

pb = new int(5);

2 .下面**有何錯誤

void func2(int *value)

*value = 2;

void func1()

int *p = 0;

func2(p);

3 .

int func1(int& b)

return 0;

void func2()

int bbb = 3;

func1(&bbb);

func1(bbb);

func2 中有何錯誤, func1 的引數 b 的型別是什麼。

三.簡答題 (64 分 )

1. 請簡述 c 、 c++ 、 vc 、 mfc 在概念上的區別 (4 分 )

2 .請寫乙個函式過載的簡單例子 (4 分 )

3. 用什麼函式開啟新程序、執行緒。 (4 分 )

4.sendmessage 和 postmessage 有什麼區別 (4 分 )

5.waitforsingleobject 有何作用; m_pthrd 的型別是 cwinthread* 時, waitforsingleobject(m_pthrd->m_hthread, infinite); 有何作用。 (4 分 )

6. __stdcall 、 __cdecl 、 __pascal 在什麼方面有所不同。 (4 分 )

7 .請把下述**加上異常處理。 (6 分 )

int mywritefile(cstring strfilename, cstring strtext)

int nret = 0;

cfile myfile;

myfile.open(strfilename, cfile::modewrite|cfile::shareexclusive|cfile::modecreate, null);

int nlen = strtext.getlength();

myfile.write((char*)(lpcstr)strtext, nlen);

myfile.close();

return nret;

8 .請解釋「 func 」為何種型別,這種型別的作用什麼,變數 ttt 的值是多少? (6 分 )

typedef int (*func)(int, int*);

int ***(int a, int *p)

return a + *p;

int dowork(func aaa, int bbb, int *ccc)

return aaa(bbb, ccc);

int sss = 4;

int ttt = dowork(&***, 3, &sss);

9 .請問下述**中 : int operator+(… )起什麼作用? this 是什麼? ccc 的值最終為多少? (6 分 )

class fruit

public:

fruit()

weight = 2;

fruit(int w)

weight = w;

int operator+(fruit f)

return this->weight * f.weight;

private:

int weight;

fruit aaa;

fruit bbb(4);

int ccc = aaa + bbb;

10. 請解釋下面**採用了何種 c++ 特性( c 語言不具備),作用是什麼? (6 分 )

template

t sum(t a, t b)

return (a + b);

11 .請解釋 aaa.h 中下面**的功能 (5 分 )

#if !defined(afx_mysudu_h__9b952bea_a051_4026_b4e5_0598a39d2da4__included_)

#define afx_mysudu_h__9b952bea_a051_4026_b4e5_0598a39d2da4__included_

... ...

#endif

12 . cmemorystate 主要功能是什麼 (5 分 )

13 .請閱讀下述**,寫出程式執行的結果( 6 分)

#include

using namespace std;

class cbase 

public:

virtual void print()

cout<< "base" << endl;

void doprint()

print();

class cchild1: public cbase

public:

virtual void print()

cout<< "child1" << endl;

class cchild2: public cbase

public:

virtual void print()

cout<< "child2" << endl;

void doprint(cbase *base)

base->doprint();

void main()

cbase* base = new cbase();

cchild1* child1 = new cchild1();

cchild2* child2 = new cchild2();

doprint(child1);

doprint(child2);

doprint(base);

delete base;

base = child1;

base->print();

delete child1;

delete child2;

華為面試題

1 區域性變數能否和全域性變數重名?答 能,區域性會遮蔽全域性。要用全域性變數,需要使用 區域性變數可以與全域性變數同名,在函式內引用這個變數時,會用到同名的區域性變數,而不會用到全域性變數。對於有些編譯器而言,在同乙個函式內可以定義多個同名的區域性變數,比如在兩個迴圈體內都定義乙個同名的區域性變數...

華為面試題

三 1 區域性變數能否和全域性變數重名?答案 能,區域性會遮蔽全域性。要用全域性變數,需要使用 區域性變數可以與全域性變數同名,在函式內引用這個變數時,會用到同名的區域性變數,而不會用到全域性變數。對於有些編譯器而言,在同乙個函式內可以定義多個同名的區域性變數,比如在兩個迴圈體內都定義乙個同名的區域...

華為面試題

華為面試題 q1 請你分別划划osi的七層網路結構圖,和tcp ip的五層結構圖?q2 請你詳細的解釋一下ip協議的定義,在哪個層上面,主要有什麼作用?tcp與udp呢?q3 請問交換機和路由器分別的實現原理是什麼?分別在哪個層次上面實現的?q4 請問c 的類和c裡面的struct有什麼區別?q5 ...