久久免费视频1,91精品视频在线,色综合天天综合网国产成人网,成人综合在线、,亚洲合集综合久久性色,能免费在线观看的欧洲黄色网站,粉嫩黄色wwww

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

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

更新:2023-09-18 23:12:51 高考升學網(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)容復制到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ù)。

相關(guān)文章

最新圖文

2020年河北新聞網(wǎng)兩學一做

時間:2023-09-18 07:0:24

2020年河北新聞網(wǎng)兩學一做

時間:2023-09-15 11:0:59

兩學一做學習教育知

時間:2023-09-21 06:0:30

2020年開展兩學一做學習教

時間:2023-09-19 21:0:30