Interview Question: Heap vs. Stack

Sample Question #239 (programming – C++)
Explain the difference between "stack allocation" and "heap allocation" in C++. Give some examples to illustrate your answer.
(Comment: I’ll be giving you a lot of C++ questions on this blog — which also helps distinguish this blog from most other "sample interview questions" forums you find elsewhere on the web — because my own firsthand experience indicates more and more quant interviewers will ask candidates C++ questions these days)
This entry was posted in Sample Qs. Bookmark the permalink.

2 Responses to Interview Question: Heap vs. Stack

  1. Brett says:

    There’re different ways to explain the difference between the two. One way is to say that stack allocation is performed by the compiler at compile time to allocate storage for "ordinary" variables, especially variables declared within some function block, whereas heap allocations is dynamic storage allocated at run-time, via the new function call.
    Comment: more likely, the interviewer might give you some examples, which can be tricky, and ask you whether the memoryh allocation is stack-based or heap-based. Make sure you know your C++ well!

  2. Wei says:

    Really benefit from this a lot..Please keep up with the great work!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s