I'm trying to understand the difference between stack memory and heap , and this question on SO as well as this explanation did a pretty good job explaining the basics.
In the second explanation, however, I came across an example to which I have a specific question, an example is this:

It is explained that the object m stands out on the heap , I just wonder if this is the full story. In my opinion, the object itself really stands out on the heap because the new keyword was used to create it.
However, isn't it that the pointer to the object m at the same time allocated on the stack ? Otherwise, as it were, the object itself, which, of course, sits on the heap . I feel that for the sake of completeness, this should have been mentioned in this lesson, leaving it out, which causes me some confusion, so I hope someone can clarify this and tell me that I'm right, understanding that this example should have basically two statements that would have to say:
1. The pointer to the object m was allocated on the stack
2. the object m (therefore, the data that it carries, as well as access to its methods) was allocated on the heap
c ++ memory-management pointers
nburk Jun 24 '14 at 7:37 2014-06-24 07:37
source share