I recently picked up C but am a little confused about how we reference something allocated in the heap.
For example, assume we did something as follows:
void test(){
int *a;
a = (int*)(malloc(sizeof(int)*4));
a[0] = 1;
a[1] = 2;
a[2] = 0;
a[3] = 0;
}
Now, let's say I am in main, obviously, I cannot do something like a[0]=... outside the function as there is no reference to a, but it is allocated in the heap, so how would I make a reference to it? I am guessing I'd have to return an int* or store the address to a outside the function.