You are here:

C/C programming free function

Advertisement


Question
How can i free an integer value allocated dynamically on the memory ie on heap. I am using free(q->mark). it gives me an error that argument should be of type void*

Answer
Hi Archit,

The free function expects a pointer to allocated memory. You might not be passing the correct type to free.



void free(void *ptr);

 The free() function frees the memory space pointed to by ptr, which must have been returned by a previous call to  malloc(),  calloc()  or realloc().   Otherwise,  or  if free(ptr) has already been called before, undefined behavior occurs.  If ptr is NULL, no operation is per‐formed.

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tony Nazzal

Expertise

I will answer any c language programming and syntax questions.

Experience

I have almost a decade of c programming experience.

Education/Credentials
I have a bachelor of science degree and several years of industry experience.

©2016 About.com. All rights reserved.