歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 搜狗2012.9.23校園招聘會筆試題

搜狗2012.9.23校園招聘會筆試題

日期:2017/2/28 15:30:05   编辑:Linux教程

C/C++類

1、以下程序的輸出是(12)

  1. class Base
  2. {
  3. public:
  4. Base(int j) : i(j) { }
  5. virtual ~Base() { }
  6. void func1()
  7. {
  8. i *= 10;
  9. func2();
  10. }
  11. int getValue()
  12. {
  13. return i;
  14. }
  15. protected:
  16. virtual void func2()
  17. {
  18. i++;
  19. }
  20. protected:
  21. int i;
  22. };
  23. class Child : public Base
  24. {
  25. public:
  26. Child(int j) : Base(j) { }
  27. void func1()
  28. {
  29. i *= 100;
  30. func2();
  31. }
  32. protected:
  33. void func2()
  34. {
  35. i += 2;
  36. }
  37. };
  38. int main(void)
  39. {
  40. Base *pb = new Child(1);
  41. pb->func1();
  42. cout<<pb->getValue()<<endl;
  43. delete pb;
  44. return 0;
  45. }

2、請問程序的輸出結果是(30)
#define DOUBLE(x) x+x // x*2
int i = DOUBLE(5)*5;
cout<<i<<endl;
3、寫出一下程序的輸出(死循環)

  1. int main(void)
  2. {
  3. char num;
  4. for(num = 0; num < 255; )
  5. num += num;
  6. printf("%d\n",num);
  7. return 0;
  8. }

4、程序出錯在什麼階段?()

  1. int main(void)
  2. {
  3. http://www.sogou.com
  4. cout<<"welcome to sogou"<<endl;
  5. return 0;
  6. }

A、編譯階段出錯 B、運行階段出錯 C、編譯和運行都出錯 D、程序運行正常
因為http://www.sogou.com中//後面是注釋,前面的http:是標簽(類似於goto語句中的標簽)。(這個題目碉堡了)

5、下面程序執行結果為【說明:X86_64環境】(D)

  1. int main(void)
  2. {
  3. int a[4][4] = {
  4. {1,2,3,4},
  5. {50,60,70,80},
  6. {900,1000,1100,1200},
  7. {13000,14000,15000,16000} };
  8. int (*p1)[4] = a;
  9. int (*p2)[4] = &a[0];
  10. int *p3 = &a[0][0];
  11. printf("%d %d %d %d\n",*(*(a+1)-1),*(*(p1+3)-2)+1,*(*(p2-1)+16)+2,*(p3+sizeof(p1)-3));
  12. return 0;
  13. }

A、16000 1101 13002 2
B、4 2 3 60
C、16000 2 3 2
D、4 1101 13002 60
p1為指向一維數組的指針,所以a + 1指向{50,60,70,80}這一維的地址。減一則為4的地址;同理第二個輸出1101。同理,由於數組的列是4,所以*(p2 - 1) + 16就相當於*(p2) + 12,所以第三個輸出13002。
第四個由於p1是指針,所以sizeof(p1)為8(68位的系統),所以第四個輸出60。

6、在32位操作系統gcc編譯器環境下,下面的程序的運行結果是(A)

  1. class A
  2. {
  3. public:
  4. int b;
  5. char c;
  6. virtual void print()
  7. {
  8. cout<<"this is father's function!"<<endl;
  9. }
  10. };
  11. class B : A
  12. {
  13. public:
  14. virtual void print()
  15. {
  16. cout<<"this is children's function!"<<endl;
  17. }
  18. };
  19. int main(void)
  20. {
  21. cout<<sizeof(A)<<" "<<sizeof(A)<<endl;
  22. return 0;
  23. }

A、12 12
B、8 8
C、9 9
D、12 16
7、以下哪些做法是不正確或者應該極力避免的:【多選】(ACD)
A、構造函數聲明為虛函數
B、派生關系中的基類析構函數聲明為虛函數
C、構造函數調用虛函數
D、析構函數調用虛函數

Copyright © Linux教程網 All Rights Reserved