Search code examples
c++cdynamic-memory-allocation

Where is dynamic memory allocated?


The question was asked to me in an interview and my answer was "computer memory". But where exactly..? is it the Random Access Memory or the hard drive?


Solution

  • They were probably looking for "the heap". This is an area of memory that's separate from "the stack", which is where all your local variables, parameters, return values, etc., are stored. And yes, it's all in RAM, not on the hard drive.