C + + string

Source: Internet
Author: User

1 allocation and recycling of memory for string objects

If the string is short, then the memory is allocated on the stack. If the string is long, allocate memory on the heap.

At the end of the string life cycle, the destructor of string is automatically called to free memory.

2 string object as formal parameter of function

This time the copy constructor is implicitly called, the argument object is copied, and a new object is created.

3 String Object as the return value of a function

Implicitly call the copy constructor, create a new object, and pass it back so that the memory on the stack is freed.

4 copy constructor when a new string object is created, will the string itself be copied one copy?

Will, each string object has its own string space, otherwise it is inconvenient to edit.

C + + string

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.