It compiles, first printout is 0 and the second is some address like -84551551.
But the program gives the same result without delete [ ] array.
I think it is good, it is always good to use delete.
User Profile
Collapse
-
-
I think there is a problem with the array function, it should return new array if integers.
// CODE
int *array (int n)
{
return new int(n); // should be new int[ ];
}
//
Am I wrong?Leave a comment:
-
C++ Code
What is wrong with this code?
Code:int *array (int n) { return new int(n); } int main() { int *p = array(10); for(int i = 0; i < 10; i++) { p[i]= 0; // initialize all to 0 } printf( "%d\n", p[0]); p = array(10); printf ("%d\n", p[0]); return 0; }
No activity results to display
Show More
Leave a comment: