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 |
header file stdlib.h
void * calloc( size_t nmemb, size_t size);
calloc() allocates memory for an array of nmemb elements of size bytes each and returns a pointer to the allocated memory. The memory is set to zero. If nmemb or size is 0, then calloc() returns either NULL, or a unique pointer value that can later be successfully passed to free().
nmemb : Number of elements to allocate.
size : Size of each element.
returns a pointer to the allocated memory, which is suitable for any kind of data type variable. On error, it will return NULL.
#include <stdio.h>
#include <stdlib.h>
int main ( int argc, char* argv[])
{
int * intArray;
intArray = (int *)calloc( 10, sizeof(int));
//check to see if memory allocation is success.
if( intArray)
{
//usage
int i = 0;
for( i = 0; i < 10; i++ )
{
intArray[i] = i;
}
//free after usage
free( intArray);
}
return EXIT_SUCCESS;
}
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