微軟暑期實習筆試題

sunmenggmail發表於2012-04-12

A. const char *pContent; //pContent 是指標,指向的是const char

B. char * const pContent;//pContet 首先是一個const 的變數,然後是一個指標,也就是說是一個const 的指標,指向char

C. char const *pContent;//和A一樣,因為const 可以放在型別前,也可以放在型別後

D. const char* const pContent;


5. What is the output of the follow code?
void main(int argc, char* argv[]) {
	int i = 11;
	int const *p = &i;
	p++;
	cout<<*p<<endl;
}
A. 11	B. 12	C. Garbage value	D. Comipler error	E. None of above
Choose: C

一定要仔細!!



Which of the following C++ code is correct: 
  
(A)  
  
int f() 

     int *a = new int ( 3 ); 
     return *a; 

有記憶體洩露問題
(B) 
  
int* f() 

     int a[ 3 ] = { 1, 2, 3 }; 
     return a; 

//區域性變數  
(C) 
  
vector<int> f() 

     vector<int> v( 3 ); 
     return v; 

  
(D) 
  
void f( int* ret ) 

     int a[ 3 ] = { 1, 2, 3 }; 
     ret = a; 
     return; 

//ret 是指標,形參對於指標而言,是值傳遞。對於f(a),a的值不發生任何變化

//另外要注意,int a[3] = new int [3]是錯誤的,一定要用指標
(E) 
  
none of above 

相關文章