malloc in c array code example Example 1: c allocate array int *array = malloc(10 * sizeof(int)); Example 2: how to use malloc in c ptr = (castType*) malloc(size);