Which expression dynamically allocates an array of 10 integers in C++?

Options

  • A. new int[10]
  • B. new int(10)
  • C. malloc int[10]
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. new int[10]

Detailed Explanation

Answer: (A) new int[10]

The expression new int[10] dynamically allocates storage for an array of 10 integers.

For example:

int *p = new int[10];

Here, p points to the first element of the dynamically allocated array.

The important difference is that new int[10] creates an array, whereas new int(10) creates a single integer initialized with the value 10.