11.07.2015 Views

PicC 9.50 dsPIC Manual.pdf

PicC 9.50 dsPIC Manual.pdf

PicC 9.50 dsPIC Manual.pdf

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Library FunctionsMALLOCSynopsis#include void * malloc (size_t cnt)DescriptionThe malloc() function attempts to allocate cnt bytes of memory from the "heap", the dynamic memoryallocation area. If successful, it returns a pointer to the block, otherwise zero is returned. Thememory so allocated may be freed with free(), or changed in size via realloc(). The malloc() routinecalls sbrk() to obtain memory, and is in turn called by calloc(). The malloc() function does not clearthe memory it obtains, unlike calloc().Example#include #include #include voidmain (void){char * cp;}cp = malloc(80);if(!cp)printf("Malloc failed\n");else {strcpy(cp, "a string");printf("block = ’%s’\n", cp);free(cp);}163

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!