C Programming Language |
malloc |
calloc |
memset |
memcpy |
memory |
strcpy |
string |
strtok |
isalnum |
cctype |
errno |
cfenv |
clock |
difftime |
mktime |
ctime |
fprintf |
fscanf |
printf |
scanf |
stdio |
math |
Defined in header - stdlib.h
void* malloc( size_t size);
Allocates size bytes of uninitialized storage.
If allocation succeeds, returns a pointer to the lowest (first) byte in the allocated memory block that is suitably aligned for any object type
size - number of bytes to allocate.
On success, returns the pointer to the beginning of newly allocated memory. The returned pointer must be deallocated with free() or realloc() to avoid memory leaks after usage.
On failure, returns a null pointer.
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char* argv[])
{
char * str = (char *) malloc( (sizeof(char) * 100));
if(!str)
{
printf("memory allocation failed!\n");
}
return EXIT_SUCCESS;
}
The above program allocates 100 char memory, and returns pointer to the allocated block.
zalloc is a third party library
posted on 2018-12-12 20:46:30 - C Programming Language Tutorials
posted on 2017-12-29 22:52:47 - C Programming Language Tutorials