《2013年海康威视校园招聘笔试题.doc》由会员分享,可在线阅读,更多相关《2013年海康威视校园招聘笔试题.doc(13页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、2013年海康威视校园招聘笔试题1、10、10、4、4四个数,怎么算出24点?(10*10-4)/4=242、下列表达式在32位机器编译环境下的值()cpp view plaincopyprint?1. classA2. 3. ;4. 5. classB6. 7. public:8. B();9. virtualB();10. ;11. 12. classC13. 14. private:15. #pragmapack(4)16. inti;17. shortj;18. floatk;19. charl64;20. longm;21. char*p;22. #pragmapack()23. ;
2、24. 25. classD26. 27. private:28. #pragmapack(1)29. inti;30. shortj;31. floatk;32. charl64;33. longm;34. char*p;35. #pragmapack()36. ;37. 38. intmain(void)39. 40. printf(%dn,sizeof(A);41. printf(%dn,sizeof(B);42. printf(%dn,sizeof(C);43. printf(%dn,sizeof(D);44. return0;45. class A;class Bpublic:B()
3、;virtual B();class Cprivate:#pragma pack(4)int i;short j;float k;char l64;long m;char *p;#pragma pack();class Dprivate:#pragma pack(1)int i;short j;float k;char l64;long m;char *p;#pragma pack();int main(void)printf(%dn,sizeof(A);printf(%dn,sizeof(B);printf(%dn,sizeof(C);printf(%dn,sizeof(D);return
4、0;A、1、4、84、82 B、4、4、82、84 C、4、4、84、82 D、1、4、82、823、以下程序在32位机器下运行的结果是()cpp view plaincopyprint?1. #pragmapack(4)2. structinfo_t3. 4. unsignedcharversion;5. unsignedcharpadding;6. unsignedcharextension;7. unsignedcharcount;8. unsignedcharmarker;9. unsignedcharpayload;10. unsignedshortsequence;11. unsi
5、gnedinttimestamp;12. unsignedintssrc;13. ;14. 15. unioninfo_u16. 17. unsignedcharversion;18. unsignedcharpadding;19. unsignedcharextension;20. unsignedcharcount;21. unsignedcharmarker;22. unsignedcharpayload;23. unsignedshortsequence;24. unsignedinttimestamp;25. unsignedintssrc;26. ;27. #pragmapack(
6、)28. 29. intmain(void)30. 31. printf(%dn,sizeof(info_t);32. printf(%dn,sizeof(info_u);33. return0;34. #pragma pack(4)struct info_tunsigned char version;unsigned char padding;unsigned char extension;unsigned char count;unsigned char marker;unsigned char payload;unsigned short sequence;unsigned int ti
7、mestamp;unsigned int ssrc;union info_uunsigned char version;unsigned char padding;unsigned char extension;unsigned char count;unsigned char marker;unsigned char payload;unsigned short sequence;unsigned int timestamp;unsigned int ssrc;#pragma pack()int main(void)printf(%dn,sizeof(info_t);printf(%dn,s
8、izeof(info_u);return 0;A、12 12 B、12 4 C、16 4 D、16 12 E、16 14、以下表达式result的值是()cpp view plaincopyprint?1. #defineVAL1(a,b)a*b2. #defineVAL2(a,b)a/b-3. #defineVAL3(a,b)+a%b4. 5. inta=1;6. intb=2;7. intc=3;8. intd=3;9. inte=5;10. 11. intresult=VAL2(a,b)/VAL1(e,b)+VAL3(c,d);#define VAL1(a,b) a*b#define V
9、AL2(a,b) a/b-#define VAL3(a,b) +a%bint a = 1;int b = 2;int c = 3;int d = 3;int e = 5;int result = VAL2(a,b)/VAL1(e,b)+VAL3(c,d);A、-2 B、1 C、0 D、25、请写出以下程序的输出(5分)cpp view plaincopyprint?1. voidswap_1(inta,intb)2. 3. intc;4. c=a;5. a=b;6. b=c;7. return;8. 9. voidswap_2(int&a,int&b)10. 11. intc;12. c=a;
10、13. a=b;14. b=c;15. return;16. 17. voidswap_3(int*a,int*b)18. 19. intc;20. c=*a;21. *a=*b;22. *b=c;23. return;24. 25. 26. intmain(void)27. 28. inta=100;29. intb=200;30. swap_1(a,b);31. printf(a=%d,b=%dn,a,b);32. swap_2(a,b);33. printf(a=%d,b=%dn,a,b);34. swap_3(&a,&b);35. printf(a=%d,b=%dn,a,b);36.
11、return0;37. void swap_1(int a , int b)int c;c = a;a = b;b = c;return ;void swap_2(int &a , int &b)int c;c = a;a = b;b = c;return ;void swap_3(int *a , int *b)int c;c = *a;*a = *b;*b = c;return ;int main(void)int a = 100;int b = 200;swap_1(a , b);printf(a = %d , b = %dn,a , b);swap_2(a , b);printf(a
12、= %d , b = %dn,a , b);swap_3(&a , &b);printf(a = %d , b = %dn,a , b);return 0;输出结果:a = 100 , b = 200a = 200 , b = 100a = 100 , b = 2006、下面的程序是否有问题,如有问题,请重构代码(5分)cpp view plaincopyprint?1. voidtest_type(boolb,constchar*p,floatf)2. 3. if(!b)4. 5. return;6. 7. elseif(!p)8. 9. return;10. 11. elseif(!f)1
13、2. 13. return;14. 15. void test_type(bool b , const char *p , float f)if(!b)return ;else if(!p)return ;else if(!f)return ;修改如下:cpp view plaincopyprint?1. voidtest_type(boolb,constchar*p,floatf)2. 3. if(!b)4. 5. return;6. 7. elseif(!p)8. 9. return;10. 11. elseif(f-1e-10&f -1e-10 & f SayHello();54. b1
14、-SayWorld();55. 56. b2-SayHello();57. b2-SayWorld();58. 59. d-SayHello();60. d-SayWorld();61. 62. deleted;63. deleteb2;64. deleteb1;65. 66. d=NULL;67. b2=NULL;68. b1=NULL;69. 70. return0;71. class Basepublic:Base()printf(I am Base()n);virtual Base()printf(I am Base()n);public:virtual void SayHello()
15、printf(Hello Basen);void SayWorld()printf(World Basen);class Derived : public Basepublic:Derived()printf(I am Derived()n);virtual Derived()printf(I am Derived()n);public:void SayHello();void SayWorld();void Derived:SayHello()printf(Hello Derivedn);void Derived:SayWorld()printf(World Derivedn);int ma
16、in(void)Base *b1 = new Base;Base *b2 = new Derived;Derived *d = new Derived;b1-SayHello();b1-SayWorld();b2-SayHello();b2-SayWorld();d-SayHello();d-SayWorld();delete d;delete b2;delete b1;d= NULL;b2 = NULL;b1 = NULL;return 0;输出结果:I am Base()I am Base()I am Derived()I am Base()I am Derived()Hello Base
17、World BaseHello DerivedWorld BaseHello DerivedWorld DerivedI am Derived()I am Base()I am Derived()I am Base()I am Base()11、阅读以下程序并给出执行结果cpp view plaincopyprint?1. classBclass2. 3. public:4. Bclass(inti,intj)5. 6. x=i;7. y=j;8. 9. virtualintfun()10. 11. return0;12. 13. protected:14. intx,y;15. ;16. 1
18、7. classlclass:publicBclass18. 19. public:20. lclass(inti,intj,intk):Bclass(i,j)21. 22. z=k;23. 24. intfun()25. 26. return(x+y+z)/3;27. 28. private:29. intz;30. ;31. intmain(void)32. 33. lclassobj(2,4,10);34. Bclassp1=obj;35. coutp1.fun()endl;36. 37. Bclass&p2=obj;38. coutp2.fun()endl;39. coutp2.Bcl
19、ass:fun()endl;40. 41. Bclass*p3=&obj;42. coutfun()endl;43. 44. return0;45. class Bclasspublic:Bclass(int i , int j)x = i;y = j;virtual int fun()return 0;protected:int x , y;class lclass : public Bclasspublic:lclass(int i , int j , int k) : Bclass(i , j)z = k;int fun()return (x+y+z)/3;private:int z;i
20、nt main(void)lclass obj(2,4,10);Bclass p1 = obj;coutp1.fun()endl;Bclass &p2 = obj;coutp2.fun()endl;coutp2.Bclass:fun()endl;Bclass *p3 = &obj;coutfun()endl;return 0;输出结果:050512、如何减少频繁分配内存(malloc或者new)造成的内存碎片?(10分)13、请写出strchr的实现(10分)函数功能:找出在字符串str中第一次出现字符ch的位置,找到就返回该字符位置的指针(也就是返回该字符在字符串中的地址的位置),找不到就返
21、回空指针(就是NULL)const char* strchr(const char* str , char ch)cpp view plaincopyprint?1. constchar*strchr(constchar*str,charch)2. 3. char*p=NULL;4. constchar*s=str;5. for(;*s!=0;+s)6. 7. if(*s=ch)8. 9. p=(char*)s;10. break;11. 12. 13. returnp;14. const char* strchr(const char* str , char ch)char *p = NULL;const char* s = str;for( ; *s != 0 ; +s)if(*s = ch)p = (char *)s;break;return p;14、请写出冒泡排序法算法(20分)void BubbleSort(int r , int n);cpp view plaincopyprint?1. voidBubbleSort(intr,intn)2. 3. inti,j,temp;4. for(i=0;in-1;+i)5. 6. for(j=0;jrj+1)9. 10. temp=rj;11. rj=rj+1;12. rj+1=temp;13. 14. 15. 16.
限制150内