0

I have a question about the new operator to allocate array in c++:

int * foo;
foo = new int [5];

in this case, the foo point to a array of int, but how about change the code to:

foo = new int [0];

what is allocated and what will happen?

ratzip
  • 1,571
  • 7
  • 28
  • 53

1 Answers1

0

Nothing is allocated, and using that pointer will invoke undefined behavior.

horns
  • 1,843
  • 1
  • 19
  • 26
  • Memory may be allocated as a result. Dereferencing the pointer is undefined, but "using" is too vague. It's allowed to copy the pointer or print its value, for example. The pointer should still be deleted. – Neil Kirk Feb 11 '15 at 13:17