How to dynamically allocate arrays in C++
问题 I know how to dynamically allocate space for an array in C. It can be done as follows: L = (int*)malloc(mid*sizeof(int)); and the memory can be released by: free(L); How do I achieve the equivalent in C++? Specifically, how do I use the new and delete[] keywords? Especially in the context of creating/destroying a linked list node, or creating and destroying an array whose size is given by a variable during compile time? 回答1: L = new int[mid]; delete[] L; for arrays (which is what you want) or