In c++, what happens if allocate memory size by zero?
A zero sized array is valid.
You just can't de-reference any members.
This is why the Greeks spent such a long time debating it thinking about zero as a number. But we can thank India at its great minds for eventually bringing zero as a number 0. It took them forever and aren't we glad they did, a lot of modern maths would not be possible without such a unique value.
after allocation I get valid memory pointer,
That is correct.
If it failed it would throw an exception.
and prints valid number.
Your assignment: p = &a;
is probably not what you want. As this just leaks memory and set p to point at the variable a. What you were probably trying to do is:
(*p) = a;
// or
p[0] = a;
This is undefined behavior.
As you are assigning to values after the end of the array.
But I think new operator should return something like FAILD or NULL.
No.
Can anybody explain detail?
Yes.