What do malloc(); and free(); do?
What are they used for? Could somebody please show me an example?
Also, what header files do i include to use these functions?
I use MSVC++ 6!
Cya.
What do malloc(); and free(); do?
What are they used for? Could somebody please show me an example?
Also, what header files do i include to use these functions?
I use MSVC++ 6!
Cya.
malloc is used for dynamic memory allocation, free is used to free the memory allocated by malloc (or calloc, realloc)
read the manual pages for more information
example:Code:#include <stdio.h> #include <stdlib.h> /* needed for malloc, free */ int main(void) { char *msg; msg = malloc(13); /* allocate memory (13 bytes) */ if(msg == NULL) return -1; strcpy(msg, "Hello world!"); printf("%s\n", msg); free(msg); return 0; }