Here is how I malloc an int var and then access this var outside of the function
int f1(int ** b) { *b = malloc(sizeof(int)); **b = 5; } int main() {
Instead of malloc()ing a single int, malloc the array.
malloc()
malloc
int f1(int * b) { b = malloc(ARRAY_LENGTH * sizeof(int)); *b = 5; b[1] = 6; *(b + 2) = 7; }