Wednesday, October 31, 2018

Static and dynamic memory allocation in C++

Why the following guess is wrong ? (a software engineering company manager told me that it's almost correct but I don't understand why and I can't search for the answer in the Internet..)




int* ptr = new int;      // Sorry I mistyped before


My claim :




  1. left part (ptr) is of static memory allocation.

  2. right part (new int) is of dynamic memory allocation.




// new edited : 1 Jan 2015 17:39 (UTC +08:00)
what I am thinking is,
It moves the pointer of stack down(or up?) to free a space for ptr.
And find a empty space for a new int.
And then store the address of this new int to ptr.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...