Anything Wrong With This Code
Here, you have declared a pointer named "p" and initialized that with a "0". After that you are using the delete operator (without using dynamic memory new operator)that is meant to be used after the new operator.
You should use this:
int *p; // declared a new pointer
p = new int; // allocate a dynamic memory through this pointer
*p = 0; // assign value to the dynamic memory
delete p; // after using pointer, finally you have to deallocate that memory
p = NULL; // and finally pointer should be assign a NULL
Hope it would help a bit.
T *p = 0;delete p;Yes, the program will crash in an attempt to delete a null pointer.
2009-2016 downloadmela.com. All rights reserved.