<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. 假如我是池中的一朵荷花作文

    時間:2025-07-08 11:07:40 荷花 我要投稿

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

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

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

      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 數組的方法有什么錯誤?【基礎】

      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 循環中的變量i 的類型不應定義為vector::size_type,

      因為該類型為無符號數值類型,故循環條件將恒成立,為死循環,應將其類型定

      義為有符號的int 類型。

      以下代碼有什么問題?【基礎】

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

      答:運算符中兩個可選值的類型不同。

      以下代碼有什么問題?【基礎】

      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 循環中的if 語句后的array.erase(itor)語句,它將迭代器itor 所指

      向的元素刪除后會自動下移一位,故應在其后加上語句:itor–;

      以下代碼中的兩個sizeof 用法有問題嗎?【基礎】

      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 循環的sizeof(str)的值將總是4,所以該方法

      只能將參數中的字符串的前四個字符轉換成大寫字母。

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

      unsigned int const size1 = 2;

      char str1[size1];

      unsigned int temp = 0;

      cin >> temp;

      unsigned int const size2 = temp;

      char str2[size2];

      答:能;

      以下代碼有什么問題?【基礎】

      struct Test{

      Test(int){}

      Test(){}

      void fun(){}

      };

      void main(void){

      Test a(1);

      a.fun();

      Test b();

      b.fun();

      }

      答:main 函數的返回類型應為int;不能對b 調用fun()方法。

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

      struct CLS{

      int m_i;

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

      CLS(){ CLS(0);}

      };

      int main(){

      CLS obj;

      cout <

      }

      答:輸出不是0;

      C++中的空類,默認產生哪些類成員函數?【基礎】

      答:空類中默認包含的成員函數如下:

      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>

      };

      統計一篇文章中單詞個數。【基礎】

      答:代碼如下:

      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;

      }

      寫一個函數,完成內存之間的拷貝。【中等難度】

      答:代碼如下:

      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++內建類型A 和B,在哪幾種情況下B 能隱式轉化為A?【較難】

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

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

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

      (可以有其他帶帶默認值的參數)

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

      但也可以勉強算一個

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

      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。

    【假如我是池中的一朵荷花作文】相關文章:

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

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

    一朵荷花作文11-27

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

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

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

    假如我是一朵云05-05

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

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

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

    • 相關推薦
    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人