Hi
I am new to c programming language,
I have written this small code and I dont know why cant i use the free() here, any clarification highly appreciated.
int insert(element **head, int d)
{
element *temp;
temp = (element*)malloc(sizeof(element));
if(temp == NULL)
{
printf("\nError: Failure to allocate memory\n");
exit(1);
}
temp->data = d;
temp->next = *head;
*head = temp;
free(temp); // --->>> why ? cant i use free() here ?
temp = NULL;
return 1;
}
Also, could you give a small basic example of where free may be used.
Thanks.