I have a question about malloc free order

Asked 2 years ago, Updated 2 years ago, 77 views

Why is it that I have to do the reverse free for the malloc order?

malloc

2022-09-22 14:11

1 Answers

It doesn't matter the order.

If you reallocate malloc to a pointer of memory, you have to do the opposite of free. I think this is your intention.

For example, if you assign A to malloc and B of A->B to malloc, you should free B and then free A. If A is free, B remains in memory, but B is not able to free B because B's address is unknown (because it flew away).


2022-09-22 14:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.