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