Consider this code:
int *p = new int;
cout << sizeof(*p);
delete p;
As expected, the result is 4. Now consider this other code:
int *p = new int[10];
cout << sizeof(*p);
delete[] p;
I expected to get 40 (the size of the allocated array), however the result is still 4 .
Now suppose I have a function int *foo()that returns a pointer to a structure created using newor using new[](but I don't know which one):
int *p = foo();
My question is: is there a way (or hack) to know if pa single integer or an array of integers points to ?
Please keep in mind that this is just a theoretical question. I will not write real code this way.
source
share