亚洲国产日韩欧美在线a乱码,国产精品路线1路线2路线,亚洲视频一区,精品国产自,www狠狠,国产情侣激情在线视频免费看,亚洲成年网站在线观看

假如我是池中的一朵荷花作文

時(shí)間:2025-07-08 11:07:40 荷花 我要投稿

假如我是池中的一朵荷花作文

  以下三條輸出語句分別輸出什么?【基礎(chǔ)】

假如我是池中的一朵荷花作文

  char str1[] = “abc”;

  char str2[] = “abc”;

  const char str3[] = “abc”;

  const char str4[] = “abc”;

  const char* str5 = “abc”;

  const char* str6 = “abc”;

  cout << boolalpha << (str1==str2) << endl; /pic/p>

  cout << boolalpha << (str3==str4) << endl; /pic/p>

  cout << boolalpha << (str5==str6) << endl; /pic/p>

  答:輸出為:false、false、true。

  以下反向遍歷array 數(shù)組的方法有什么錯(cuò)誤?【基礎(chǔ)】

  vector array;

  array.push_back(1);

  array.push_back(2);

  array.push_back(3);

  /pic/p>

  for(vector::size_type i=array.size()-1; i>=0; –i){

  cout << array[i] << endl;

  }

  答:for 循環(huán)中的變量i 的類型不應(yīng)定義為vector::size_type,

  因?yàn)樵擃愋蜑闊o符號數(shù)值類型,故循環(huán)條件將恒成立,為死循環(huán),應(yīng)將其類型定

  義為有符號的int 類型。

  以下代碼有什么問題?【基礎(chǔ)】

  cout << (true ? 1 : “1″) << endl;

  答:運(yùn)算符中兩個(gè)可選值的類型不同。

  以下代碼有什么問題?【基礎(chǔ)】

  typedef vector IntArray;

  IntArray array;

  array.push_back(1);

  array.push_back(2);

  array.push_back(2);

  array.push_back(3);

  /pic/p>

  for(IntArray::iterator itor=array.begin(); itor!=array.end();

  ++itor){

  if(2==*itor) {

  array.erase(itor);

  }

  }

  答:for 循環(huán)中的if 語句后的array.erase(itor)語句,它將迭代器itor 所指

  向的元素刪除后會自動(dòng)下移一位,故應(yīng)在其后加上語句:itor–;

  以下代碼中的兩個(gè)sizeof 用法有問題嗎?【基礎(chǔ)】

  void upperCase(char str[]){ /pic/p>

  for(int i=0; i if(‘a’<=str[i] && str[i]<=’z')

  str[i] -= (‘a’-'A’);

  }

  }

  int main(){

  char str[] = “aBcDe”;

  cout << “str 字符串長度為:” << sizeof(str)/sizeof(str[0]);

  cout << endl;

  upperCase(str);

  cout << str << endl;

  return 0;

  }

  答:在upperCase 方法中,for 循環(huán)的sizeof(str)的值將總是4,所以該方法

  只能將參數(shù)中的字符串的前四個(gè)字符轉(zhuǎn)換成大寫字母。

  以下代碼能夠編譯通過嗎?為什么?【基礎(chǔ)】

  unsigned int const size1 = 2;

  char str1[size1];

  unsigned int temp = 0;

  cin >> temp;

  unsigned int const size2 = temp;

  char str2[size2];

  答:能;

  以下代碼有什么問題?【基礎(chǔ)】

  struct Test{

  Test(int){}

  Test(){}

  void fun(){}

  };

  void main(void){

  Test a(1);

  a.fun();

  Test b();

  b.fun();

  }

  答:main 函數(shù)的返回類型應(yīng)為int;不能對b 調(diào)用fun()方法。

  以下代碼中的輸出語句輸出0 嗎?為什么?【基礎(chǔ)】

  struct CLS{

  int m_i;

  CLS(int i):m_i(i){ }

  CLS(){ CLS(0);}

  };

  int main(){

  CLS obj;

  cout <

  }

  答:輸出不是0;

  C++中的空類,默認(rèn)產(chǎn)生哪些類成員函數(shù)?【基礎(chǔ)】

  答:空類中默認(rèn)包含的成員函數(shù)如下:

  class Empty{

  public:

  Empty(); /pic/p>

  Empty( const Empty& ); /pic/p>

  ~Empty(); /pic/p>

  Empty& operator=( const Empty& ); /pic/p>

  Empty* operator&(); /pic/p>

  const Empty* operator&() const; /pic/p>

  };

  統(tǒng)計(jì)一篇文章中單詞個(gè)數(shù)!净A(chǔ)】

  答:代碼如下:

  include

  #include

  using namespace std;

  int main(){

  ifstream fin(“t.txt”);

  if(!fin){

  cout<<”can’t open file”< return -1;

  }

  int count = 0;

  char buf[256];

  memset(buf, 0, 256);

  while(1){

  fin2>>buf;

  if(fin2.eof())

  break;

  count++;

  }

  cout<<”The number of the words is : “< fin2.close();

  return 0;

  }

  寫一個(gè)函數(shù),完成內(nèi)存之間的拷貝。【中等難度】

  答:代碼如下:

  void* mymemcpy(void* dest, const void* src, size_t count){

  char* pdest = static_cast(dest);

  const char* psrc = static_cast(src);

  if(pdest>psrc && pdest for(size_t i=count-1; i!=-1; –i){

  pdest[i] = psrc[i];

  }

  }else{

  for(size_t i=0; i pdest[i] = psrc[i];

  }

  }

  return dest;

  }

  int main(){

  char str[] = “0123456789″;

  mymemcpy(str+1, str+0, 9);

  cout << str << endl; /pic/p>

  return 0;

  }

  非C++內(nèi)建類型A 和B,在哪幾種情況下B 能隱式轉(zhuǎn)化為A?【較難】

  答:a)class B : public A{……}/pic/p>

  b)class B{operator A();}/pic/p>

  c)class A{ A(const B&);}/pic/p>

  (可以有其他帶帶默認(rèn)值的參數(shù))

  d)A& operator= (const A&);/pic/p>

  但也可以勉強(qiáng)算一個(gè)

  以下代碼有什么問題?【較難】

  void char2Hex(char c){ /pic/p>

  char ch = c/0×10 + ’0′;

  if(ch>’9′) ch += (‘A’-’9′-1);

  char cl = c%0×10 + ’0′;

  if(cl>’9′) cl += (‘A’-’9′-1);

  cout << ch << cl << ‘ ‘;

  }

  int main(){

  char str[] = “I love 中國”;

  for(size_t i=0; i char2Hex(str[i]);

  cout << endl;

  return 0;

  }

  答:

  以下兩條輸出語句分別輸出什么?【較難】

  float a = 1.0f;

  cout << (int)a << endl;

  cout << (int&)a << endl;

  cout << boolalpha << ((int)a==(int&)a) << endl; /pic/p>

  float b = 0.0f;

  cout << (int)b << endl;

  cout << (int&)b << endl;

  cout << boolalpha << ((int)b==(int&)b) << endl;/pic/p>

  答:第一處輸出false,第二處輸出true。

【假如我是池中的一朵荷花作文】相關(guān)文章:

假如我是一朵荷花作文四篇12-11

假如我是一朵荷花優(yōu)秀作文(通用15篇)03-27

一朵荷花作文11-27

假如我是一朵菊花作文08-06

假如我是一朵小花作文03-19

作文假如我是一朵云03-25

假如我是一朵云05-05

假如我是荷花作文(精選20篇)02-25

假如我是一朵綠色的云06-09

假如我是一朵花兒作文03-24

  • 相關(guān)推薦