how to use calloc in c code example
Example 1: allocate memory c
ptr = (castType*) malloc(size);
int *exampl = (int*) malloc(sizeof(int));
ptr = (castType*) calloc(n, size);
char *exampl = (char*) calloc(20, sizeof(char));
Example 2: c calloc
void *ptr = malloc(sizeof(Type) * n_elem);
void *ptr = calloc(n_elem, sizeof(Type));
Example 3: how to dynamically allocate array size in c
int *p_array;
double *d_array;
p_array = (int *)malloc(sizeof(int)*50);
d_array = (int *)malloc(sizeof(double)*100);
for(i=0; i < 50; i++) {
p_array[i] = 0;
}
double *dptr = d_array;
for(i=0; i < 50; i++) {
*dptr = 0;
dptr++;
}
Example 4: c malloc array
#define ARR_LENGTH 2097152
int *arr = malloc (ARR_LENGTH * sizeof *arr);
Example 5: calloc
void *calloc(size_t nitems, size_t size)