歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

搜狗2012.9.23校園招聘會筆試題

C/C++類

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

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

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

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

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

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

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

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

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

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

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

Copyright © Linux教程網 All Rights Reserved