title: char* = new char And char* = new char[N]
body: <p>I construct a class named CMyString, here is it:</p>
  
  <pre><code>class CMyString {
  public:
      CMyString();
      CMyString(char* pData);
      CMyString(const CMyString&amp; str);
      ~CMyString(void);
  
      char* getData();
      void setData(char* pData);
  
      CMyString&amp; operator=(const CMyString&amp; str);
  
  private:
      char* m_pData;
  };
  
      CMyString::CMyString() {
      m_pData = new char;
  }
  
  CMyString::CMyString(char* pData) {
  //    m_pData = new char;
      m_pData = pData;
  }
  
  CMyString::CMyString(const CMyString&amp; str) {
      // 为指针分配内存
  //    m_pData = new char;
      // 拷贝值
      m_pData = str.m_pData;
  }
  
  CMyString::~CMyString(void) {
  //    delete m_pData;
  }
  
  CMyString&amp; CMyString::operator=(const CMyString&amp; str) {
      if (this == &amp;str)
          return *this;
  
      delete m_pData;
      m_pData = nullptr;
      m_pData = new char[strlen(str.m_pData) + 1];
      strcpy(m_pData, str.m_pData);
  
      return *this;
  }
  
  char* CMyString::getData() {
      return m_pData;
  }
  
  void CMyString::setData(char *pData) {
      m_pData = pData;
  }
  </code></pre>
  
  <p>And here is my main.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "CMyString.h"
  
  using std::cout;
  using std::endl;
  
  int main() {
      char* pData = "What are you worrying about?";
      std::cout &lt;&lt; pData &lt;&lt; std::endl;
  
      cout &lt;&lt; strlen(pData) &lt;&lt; endl;
      char* test = new char[30];
      cout &lt;&lt; sizeof(test) &lt;&lt; endl;
      char* test2 = new char;
      test2 = "23";
      cout &lt;&lt; test2 &lt;&lt; endl;
  
      strcpy(test, pData);
  
      cout &lt;&lt; endl &lt;&lt; test &lt;&lt; endl &lt;&lt; endl;
  
      CMyString str(pData);
      std::cout &lt;&lt; str.getData() &lt;&lt; std::endl;
  
      CMyString str2, str3;
      str3 = str2 = str;
  
      std::cout &lt;&lt; str3.getData() &lt;&lt; endl;
  
      char* pData2 = "Data has been changed.";
      str3.setData(pData2);
  
      cout &lt;&lt; str.getData() &lt;&lt; endl;
      cout &lt;&lt; str2.getData() &lt;&lt; endl;
      cout &lt;&lt; str3.getData() &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>
  
  <p>then I'm confused by the </p>
  
  <pre><code>char* pData = new char;
  char* pData2 = new char[30];
  </code></pre>
  
  <p>Am I right in the class implementation? 
  How can I tell the two different pointers?
  Do I write the constructor and de-constructor function and the operator= correctly? if not, how to write them?</p>