User loginNavigationTake FREE online C/C++ test now!Unix / Linux ProgrammingCode search made simpleYour feedback needed!As a webmaster of this site, I regard you as our most important critic and commentator. We value your opinion and want to know what we are doing right, what we could do better and any other words of wisdom you're willing to pass our way. It would be our greatest motivation which will help us in developing areas you would like to see in this site. We hope you will continue to encourage and support us in our future endeavors.
INDIA |
Bug of the week - Memory allocation conflictFind the bug in the following code snippet related to memory allocation conflict.
/* File: newfree.cpp */
#include <iostream.h>
#include <stdlib.h>
int main()
{
char *ptr;
ptr = new char;
free(ptr);
return 0;
}
Solution: Use delete(ptr); instead of free(ptr); since the memory is allocated with new operator. Note: Always use new with delete and malloc with free.
|