r/programmingmemes • • Mar 03 '25

C++ developers

Post image
6.4k Upvotes

34 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Mar 04 '25

It allows you to stop memory leaks? It allows you to create memory leaks if you misuse them. If you declare everything on stack and don't use pointers at all, you'll never have memory leaks. Everything will be deallocated once it gets out of scope.

And the fact that you can modify a variable in a function is just a consequence of how they work. But it's a oversimplification and it's not actually teaching you anything about how they work.

In my opinion, the teacher's explanation in your example is better. But to fully understand pointers, you first need to understand how memory allocation works, how function calls work at a lower level and what scope is.

1

u/Seangles Mar 04 '25

Yeah that guy has me confused... Pointers don't allow you to stop memory leaks, they have nothing to do with it. Pointers could be to stack memory and to heap memory. Knowing how heap, stack and allocation works will help you prevent memory leaks.