Week Nineth-Program Reading

Source: Internet
Author: User
/*copyright (c) 2016, *all Rights reserved, School of computer and Control engineering, Yantai University. * File name: My.cpp *    Creator: Businessman * Completion date: May 6, 2016 * * Problem Description: Read the program, write out the results of the program and understand its operating mechanism. */#include <iostream> #include <cstring>using namespace Std;class a{  char *a;  Public:      A (a &t);      A (char *aa)     {          a=new char[strlen (aa) +1];//The significance of this is that the memory space can be dynamically allocated, according to actual needs, more efficient use of memory;          strcpy (A,AA);// Data member a relates to the form parameter AA: AA is a parameter, returns a value according to the length of AA, +1 is the ending character, and then a string of AA is copied to a.      }      ~a () {      delete[]a;//when the main function ends, the destructor is performed, freeing previously dynamically allocated memory.      }     void output () {cout<<a<<endl;}}; A::a (A &t) {a=new Char[strlen (T.A) +1];//The significance of this is: can dynamically allocate memory space, according to actual needs, more efficient use of memory;          strcpy (A,T.A);} int main () {    A A ("Good monring, Code monkeys!");    A.output ();    A B (a);    B.output ();    return 0;}

Week Nineth-Program Reading

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.