[Solved] C. malloc() and free() in function doesn’t work [duplicate]


In the first code snippet you’re passing the value of the numbers variable. In the function you change a local variable, and doing so has no effect on the variable is the calling function.

In the second snippet you correctly pass the address of numbers so it can be set in the function, and the call to free is also correct. Just don’t attempt to use the value of numbers after you free it, otherwise it’s undefined behavior.

3

solved C. malloc() and free() in function doesn’t work [duplicate]