void free ( void * x );
u have to remember that u r working with a pointer,a pointer is just a variable where a memory address is stored.
so
Code:
char *x=(char*)malloc(20);
free(x);
this will work;
but
Code:
char *x=(char*)malloc(20);
x="wwwww"; //this reassigns memory address stored at x.
free(x);
this will generate an error;
because free can only be used on a previously allocated memory block,but here x is pointing to the start address of the array "wwww" .
so if u want to use the free ,your code should look like this:
Code:
#include<stdlib.h>
main(){
char *pResp;
char *pTemp;
pResp=(char*) malloc(20);
pTemp ="wwwww";
strcpy(pResp,pTemp);
printf("%s - Resp for operation\n",pResp);
free(pResp);
}