Dynamic arrays, C-style strings, string literals

Source: Internet
Author: User

Dynamic arrays

Each program consumes a piece of available memory space at execution time, which is used to hold dynamically allocated objects, which are called free stores of programs or heaps (heap). The C language uses malloc and free to allocate storage space in the heap, while the C + + language uses the new and delete expressions to achieve the same functionality.

When an array is dynamically allocated, if the array element has a class type, initialization is implemented using the class's default constructor, and no initialization if the array element is a built-in type:

string New string [ten];    // array of ten empty strings int New int [ten];              // array of ten uninitialized ints

release of dynamic space: using delete[]. In theory, the absence of square brackets on the collection of arrays results in a memory leak, at least because the runtime frees up memory space. For some system and/or element types, there may be more serious run-time errors. Therefore, don't forget the square brackets when releasing the dynamic array.

C-style string (c-style string)

The C program treats a pointer to an array of characters ending in an empty string as a string.

In C + +, string literals are C-style strings. The C standard library defines a series of library functions that handle such strings, which are placed in the CString header file in C + +. Because C-style strings are inherently error-prone, C + + programs should take precedence over C + + standard library class string and use less style string.

Dynamic arrays, C-style strings, string literals

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.