L = new int[mid]; delete[] L;
for arrays (which is what you want) or
L = new int; delete L;
for single elements.
But it’s more simple to use vector, or use smartpointers, then you don’t have to worry about memory management.
std::vector<int> L(mid);
L.data()
gives you access to the int[]
array buffer and you can L.resize()
the vector later.
auto L = std::make_unique<int[]>(mid);
L.get()
gives you a pointer to the int[]
array.
Related Posts:
- How to dynamically allocate arrays in C++
- Use new operator to initialise an array
- Is “delete this” allowed in C++?
- How do I find the length of an array?
- Initializing an array of objects
- Expression must have class type
- Passing an array by reference
- Return array in a function
- Passing an array by reference
- How to convert a char array to a string?
- What is the array form of ‘delete’?
- How do I declare a 2d array in C++ using new?
- lvalue required as left operand of assignment – Array
- Is there a function to copy an array in C/C++?
- Cleanest way to copy a constant size array in c++11
- Reverse Contents in Array
- C++ error: “Array must be initialized with a brace enclosed initializer”
- warning: ISO C++ forbids variable length array
- c++ array – expression must have a constant value
- Passing a 2D array to a C++ function
- Why use a new call with a C++ ‘vector’?
- Static array vs. dynamic array in C++
- How to create a dynamically-allocated array of const objects, but have values assigned to them?
- Fill array with random numbers within a specified range (C++)
- Remove an array element and shift the remaining ones
- How to make an array with a dynamic size? General usage of dynamic arrays (maybe pointers too)?
- How to add element to C++ array?
- How to convert vector to array
- How to find the size of an int[]?
- C++: Expression must have a constant value when declaring array inside function
- splitting a string into an array in C++ without using vector
- What’s the syntax for declaring an array of function pointers without using a separate typedef?
- Printing an array in C++?
- Delete 2D array C++
- How do you initialise a dynamic array in C++?
- Deleting an object in C++
- C++ array assign error: invalid array assignment
- How to add element to C++ array?
- Reading from .txt file into two dimensional array in c++
- extended initializer lists only available with
- Creation of Dynamic Array of Dynamic Objects in C++
- how to initialize an empty integer array in c++
- Check if C++ Array is Null
- Correct way to work with vector of arrays
- Resizing dynamic array in c++
- C++ Initializing a Global Array
- Comparing the values of char arrays in C++
- Dynamically allocated string array, then change it’s value?
- How can I assign an array from an initializer list?
- How do I return a char array from a function?
- creating an array of structs in c++
- Reading data from file into an array
- How to read lines of text from file and put them into an array
- Why can’t we pass arrays to function by value?
- Double pointer array in c++
- C++ pass an array by reference
- How to memset char array with null terminating character?
- creating dynamic array of string c++
- creating an array of structs in c++
- C++ Array of pointers: delete or delete []?
- too many initializers for ‘int [0]’ c++
- C++ 2d char array to string
- Using cin for char array
- C++ correct way to return pointer to array from function
- Warning: comparison of distinct pointer types
- how to find 2d array size in c++
- Getting error “array bound is not an integer constant before ‘]’ token”
- Using cin to input a single letter into a char
- Different ways to deallocate an array – c++
- Is C++ Array passed by reference or by pointer?
- Proper way to pass dynamic arrays to other functions
- Array of Linked Lists C++
- Conversion from ‘myItem*’ to non-scalar type ‘myItem’ requested
- C++ float array initialization
- What is an undefined reference/unresolved external symbol error and how do I fix it?
- Easiest way to convert int to string in C++
- pinpointing “conditional jump or move depends on uninitialized value(s)” valgrind message
- Why am I getting this redefinition of class error?
- error : expected unqualified-id before return in c++
- math in java – what does ” %” do?
- Unsigned keyword in C++
- How can I solve the error LNK2019: unresolved external symbol – function?
- how to define -std=c++11 as default in g++
- “g++” is not recognized as an internal or external command, MinGW
- C++ error: no matching constructor for initialization of
- How to iterate over a vector?
- What are the differences between struct and class in C++?
- What is ‘\0’ in C++?
- Process returned -1073741571 (0xC00000FD) on my c++ code
- C++ Why Is There “Unknown Type” When Class Header is Included?
- Invalid conversion from “const char*” to “char” error [duplicate]
- The system cannot find the file specified. in Visual Studio
- to_string not declared in scope
- initialize a vector to zeros C++/C++11
- When to use “new” and when not to, in C++?
- “vector” was not declared in this scope
- C++ Destructors with Vectors, Pointers,
- error C2065: ‘cout’ : undeclared identifier
- How to get the MD5 hash of a file in C++?
- Compiler error C4430: missing type specifier – int assumed [duplicate]