Click here to Skip to main content
15,790,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

How to delete a null pointer in C? Can i have a sample code.
Kornfeld Eliyahu Peter 28-Dec-15 5:48am    
You probably missed something here...Can you delete nothing?

You cannot 'delete' a null pointer.
Strictly speaking, the C programming language has no delete (it is a C++ keyword), it just provides the free[^] function. In any case, free on a null pointer does nothing.
Share this answer
A null pointer indicates that there is "nothing there" - it points at nothing. So you can't delete or free it, because you didn't assign it.

Most likely, this is an error message you are getting as a result of a problem in your code - you are trying to use a pointer that you have not assigned an address into, so the system is reporting a "null pointer" error.
Something like this:
int x = 77;
int *p;
x = x + *p;
Use the debugger: put a breakpoint on the first line of the function that shows the error and step through your code, looking at the variables and exactly what is going on. It should be fairly obvious what is causing the problem.

We can't do that for you: we can't see your screen, access your HDD, or read your mind! :laugh:
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900