When dynamically allocating an array of integers using new, which of the following syntax is correct?
- int* arr = new int;
- int arr = new int[10];
- int arr[10] = new int;
- int* arr = new int[10];
The correct way to dynamically allocate an array of integers in C++ using the new operator is int* arr = new int[10];. This syntax allocates memory for 10 integers on the heap and returns a pointer to the first element.
Loading...
Related Quiz
- In binary file operations, to write data of various data types, you use the _______ function.
- In a large-scale C++ project, two classes, Logger and FileHandler, are tightly coupled, sharing a lot of private data between them using friendship. How might you refactor these classes to reduce coupling without losing functionality?
- In a for loop, if a continue statement is executed, then the control jumps to _______.
- In C++ STL, which algorithm is most suitable for rearranging elements in a range, so they are in reversed order?
- How does C++ enforce encapsulation and abstraction in multi-level inheritance scenarios?