Which C++ operator is used to allocate memory for an array dynamically?
Options
- A. new[]
- B. malloc[]
- C. alloc[]
- D. More than one of the above
- E. None of the above
Quiz Practice:
A. new[]
Answer: new[]
The new[] expression is used to dynamically allocate memory for an array.
Example:
int *arr = new int[10];
This creates dynamic storage for 10 integers and returns a pointer to the first element.
The matching array deallocation expression is delete[].