I have a question about malloc free order

Asked 1 years ago, Updated 1 years ago, 69 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.