西西軟件園多重安全檢測(cè)下載網(wǎng)站、值得信賴的軟件下載站!
軟件
軟件
文章
搜索

首頁編程開發(fā)java → 2010年華為公司Java面試筆試題

2010年華為公司Java面試筆試題

前往專題相關(guān)軟件相關(guān)文章發(fā)表評(píng)論 來源:本站整理時(shí)間:2010/11/29 21:18:08字體大。A-A+

作者:佚名點(diǎn)擊:5543次評(píng)論:0次標(biāo)簽: 華為 Java class

  • 類型:網(wǎng)絡(luò)共享大小:6KB語言:中文 評(píng)分:3.3
  • 標(biāo)簽:
立即下載
4 頁 簡(jiǎn)答題


  1.分別寫出BOOL,int,float,指針類型的變量a 與“零”的比較語句。
  答案:
  BOOL :    if ( !a ) or if(a)
  int :     if ( a == 0)
  float :   const EXPRESSION EXP = 0.000001
           if ( a < EXP && a >-EXP)
  pointer : if ( a != NULL) or if(a == NULL)  
 
 2.請(qǐng)說出const與#define 相比,有何優(yōu)點(diǎn)?
答案:1) const 常量有數(shù)據(jù)類型,而宏常量沒有數(shù)據(jù)類型。編譯器可以對(duì)前者進(jìn)行類型安全檢查。而對(duì)后者只進(jìn)行字符替換,沒有類型安全檢查,并且在字符替換可能會(huì)產(chǎn)生意料不到的錯(cuò)誤。
2) 有些集成化的調(diào)試工具可以對(duì)const 常量進(jìn)行調(diào)試,但是不能對(duì)宏常量進(jìn)行調(diào)試! 
  3.簡(jiǎn)述數(shù)組與指針的區(qū)別?
  數(shù)組要么在靜態(tài)存儲(chǔ)區(qū)被創(chuàng)建(如全局?jǐn)?shù)組),要么在棧上被創(chuàng)建。指針可以隨時(shí)指向任意類型的內(nèi)存塊。
 (1)修改內(nèi)容上的差別
  char a[] = “hello”;
  a[0] = ‘X’;
  char *p = “world”; // 注意p 指向常量字符串
  p[0] = ‘X’; // 編譯器不能發(fā)現(xiàn)該錯(cuò)誤,運(yùn)行時(shí)錯(cuò)誤
  (2) 用運(yùn)算符sizeof 可以計(jì)算出數(shù)組的容量(字節(jié)數(shù))。sizeof(p),p 為指針得到的是一個(gè)指針變量的字節(jié)數(shù),而不是p 所指的內(nèi)存容量。C++/C 語言沒有辦法知道指針?biāo)傅膬?nèi)存容量,除非在申請(qǐng)內(nèi)存時(shí)記住它。注意當(dāng)數(shù)組作為函數(shù)的參數(shù)進(jìn)行傳遞時(shí),該數(shù)組自動(dòng)退化為同類型的指針。
  char a[] = "hello world";
  char *p = a;
  cout<< sizeof(a) << endl; // 12 字節(jié)
  cout<< sizeof(p) << endl; // 4 字節(jié)
  計(jì)算數(shù)組和指針的內(nèi)存容量
  void Func(char a[100])
  {
  cout<< sizeof(a) << endl; // 4 字節(jié)而不是100 字節(jié)
  }
  4.類成員函數(shù)的重載、覆蓋和隱藏區(qū)別?
  答案:
  a.成員函數(shù)被重載的特征:
  (1)相同的范圍(在同一個(gè)類中);
 。2)函數(shù)名字相同;
 。3)參數(shù)不同;
  (4)virtual 關(guān)鍵字可有可無。
  b.覆蓋是指派生類函數(shù)覆蓋基類函數(shù),特征是:
 。1)不同的范圍(分別位于派生類與基類);
 。2)函數(shù)名字相同;
 。3)參數(shù)相同;
 。4)基類函數(shù)必須有virtual 關(guān)鍵字。
  c.“隱藏”是指派生類的函數(shù)屏蔽了與其同名的基類函數(shù),規(guī)則如下:
 。1)如果派生類的函數(shù)與基類的函數(shù)同名,但是參數(shù)不同。此時(shí),不論有無virtual關(guān)鍵字,基類的函數(shù)將被隱藏(注意別與重載混淆)。
(2)如果派生類的函數(shù)與基類的函數(shù)同名,并且參數(shù)也相同,但是基類函數(shù)沒有virtual 關(guān)鍵字。此時(shí),基類的函數(shù)被隱藏(注意別與覆蓋混淆)  
  5. There are two int variables: a and b, don’t use “if”, “? :”, “switch”or other judgement statements, find out the biggest one of the two numbers.
  答案:( ( a + b ) + abs( a - b ) ) / 2  
  

6. 如何打印出當(dāng)前源文件的文件名以及源文件的當(dāng)前行號(hào)?
  答案:
  cout << __FILE__ ;
  cout<<__LINE__ ;
  __FILE__和__LINE__是系統(tǒng)預(yù)定義宏,這種宏并不是在某個(gè)文件中定義的,而是由編譯器定義的! 
  7. main 主函數(shù)執(zhí)行完畢后,是否可能會(huì)再執(zhí)行一段代碼,給出說明?
  答案:可以,可以用_onexit 注冊(cè)一個(gè)函數(shù),它會(huì)在main 之后執(zhí)行int fn1(void), fn2(void), fn3(void), fn4 (void);
  void main( void )
  {
  String str("zhanglin");
  _onexit( fn1 );
  _onexit( fn2 );
  _onexit( fn3 );
  _onexit( fn4 );
  printf( "This is executed first.\n" );
  }
  int fn1()
  {
  printf( "next.\n" );
  return 0;
  }
  int fn2()
  {
  printf( "executed " );
  return 0;
  }
  int fn3()
  {
  printf( "is " );
  return 0;
  }
  int fn4()
  {
  printf( "This " );
  return 0;
  }
  The _onexit function is passed the address of a function (func) to be called when the program terminates normally. Successive calls to _onexit create a register of functions that are executed in LIFO (last-in-first-out) order. The functions passed to _onexit cannot take parameters.

 8. 如何判斷一段程序是由C 編譯程序還是由C++編譯程序編譯的?
  答案:
  #ifdef __cplusplus
  cout<<"c++";
  #else
  cout<<"c";
  #endif  
  9.文件中有一組整數(shù),要求排序后輸出到另一個(gè)文件中
  答案:  
 。 nclude  
 。 nclude  
  using namespace std;  
  void Order(vector& data) //bubble sort
  {
  int count = data.size() ;
  int tag = false ; // 設(shè)置是否需要繼續(xù)冒泡的標(biāo)志位
  for ( int i = 0 ; i < count ; i++)
  {
  for ( int j = 0 ; j < count - i - 1 ; j++)
  {
  if ( data[j] > data[j+1])
  {
  tag = true ;
  int temp = data[j] ;
  data[j] = data[j+1] ;
  data[j+1] = temp ;
  }
  }
  if ( !tag )
  break ;
  }
  }  
  void main( void )
  {
  vectordata;
  ifstream in("c:\\data.txt");
  if ( !in)
  {
  cout<<"file error!";
  exit(1);
  }
  int temp;
  while (!in.eof())
  {
  in>>temp;
  data.push_back(temp);
  }
  in.close(); //關(guān)閉輸入文件流
  Order(data);
  ofstream out("c:\\result.txt");
  if ( !out)
  {
  cout<<"file error!";
  exit(1);
  }
  for ( i = 0 ; i < data.size() ; i++)
out<

    相關(guān)評(píng)論

    閱讀本文后您有什么感想? 已有人給出評(píng)價(jià)!

    • 8 喜歡喜歡
    • 3 頂
    • 1 難過難過
    • 5 囧
    • 3 圍觀圍觀
    • 2 無聊無聊

    熱門評(píng)論

    最新評(píng)論

    發(fā)表評(píng)論 查看所有評(píng)論(0)

    昵稱:
    表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
    字?jǐn)?shù): 0/500 (您的評(píng)論需要經(jīng)過審核才能顯示)