I have a void function

```
void foo(int *ptr) {
   //trying to allocate memory to hold 5 ints
   ptr = malloc(sizeof(int)*5):
   //I loop ptr and assign each with a value i =0 to 4;
}

```

In the main function I have this lines

```
int main() {
    int *num;
    //I called the function 
    foo(&(num));
    free(num);

   return 1;
}

```

I get munmap\_chunk() invalid pointer error. I did try to dig in more information, but I could not figure this out. I know it will be basic for those who work in c. I was thinking I am passing by reference and it should work, but it is not. I am new to C, and so far has been a headache.