Which operator is used in C++ to dynamically allocate memory for a single object?
Options
- A. malloc
- B. new
- C. alloc
- D. More than one of the above
- E. None of the above
Quiz Practice:
B. new
Answer: new
The new operator is used in C++ to dynamically allocate memory.
For example:
int *p = new int;
This allocates memory for an integer and returns its address, which is stored in the pointer p.
Unlike C, where malloc() is commonly used, C++ provides new as its language-level mechanism for dynamic allocation.