日韩亚洲专区中文字幕|五月天国产精品免费视频|中文字幕乱码亚州无线码二区|亚洲中文免费AV

<ul id="eu2wk"><blockquote id="eu2wk"></blockquote></ul>
  • <td id="eu2wk"><code id="eu2wk"></code></td>

    當(dāng)前位置:高考升學(xué)網(wǎng) > 招聘筆試題 > 正文

    C++ 編程筆試題和面試題答案目(二)

    更新:2023-09-18 23:12:51 高考升學(xué)網(wǎng)

    四、有關(guān)內(nèi)存的思考題(20分)

      void GetMemory(char p)

      {

      p = (char )malloc(100);

      }

      void Test(void)

      {

      char str = NULL;GetMemory(str);

      strcpy(str, "hello world");

      printf(str);

      }請問運行Test函數(shù)會有什么樣的結(jié)果?答:

      char GetMemory(void)

      {

      char p[] = "hello world";

      return p;

      }

      void Test(void)

      {

      char str = NULL;

      str = GetMemory();

      printf(str);

      }

      請問運行Test函數(shù)會有什么樣的結(jié)果?答:

      Void GetMemory2(char p, int num)

      {

      p = (char )malloc(num);

      }

      void Test(void)

      {

      char str = NULL;

      GetMemory(&str, 100);

      strcpy(str, "hello");

      printf(str);

      }

      請問運行Test函數(shù)會有什么樣的結(jié)果?答:

      void Test(void)

      {

      char str = (char ) malloc(100);

      strcpy(str, "hello");

      free(str);

      if(str != NULL)

      {

      strcpy(str, "world");

      printf(str);c

      }

      }

      請問運行Test函數(shù)會有什么樣的結(jié)果?答:

    五、編寫strcpy函數(shù)(10分)

      已知strcpy函數(shù)的原型是

      char strcpy(char strDest, const char strSrc);

      其中strDest是目的字符串,strSrc是源字符串。

      (1)不調(diào)用C++/C的字符串庫函數(shù),請編寫函數(shù) strcpy

      (2)strcpy能把strSrc的內(nèi)容復(fù)制到strDest,為什么還要char 類型的返回值?

    六、編寫類String的構(gòu)造函數(shù)、析構(gòu)函數(shù)和賦值函數(shù)(25分)

      已知類String的原型為:

      class String

      {

      public:

      String(const char str = NULL); // 普通構(gòu)造函數(shù)

      String(const String &other); // 拷貝構(gòu)造函數(shù)

      ~ String(void); // 析構(gòu)函數(shù)

      String & operate =(const String &other); // 賦值函數(shù)

      private:

      char m_data; // 用于保存字符串

      };

      請編寫String的上述4個函數(shù)。

    最新圖文