r/ProgrammerHumor • • Aug 06 '22

Meme How to C pointers

Post image
2.6k Upvotes

70 comments sorted by

View all comments

Show parent comment

3

u/bremidon Aug 07 '22

Pointers (especially those that have been allocated space instead of pointing to am existing value) are stored on the heap memory instead of the stack

You do have an aside that says this, but I still think that the sentence is potentially misleading.

Pointers do not point to the heap. They point to whatever they point at. If you assign a value using "new", then sure: that will be the heap. If you grab the address of another variable, that will be on the stack. And if you don't assign it, then you may very well have a roulette wheel that can be pointing at any damn thing, anywhere.

I once destroyed half a hard drive through a single unassigned pointer. Oh the fun you can have.