title: What is stored on heap and what is stored on stack?
body: <p>Can anyone clearly explain, in terms of C,C++ and Java.
  What all goes on stack and what all goes on Heap and when is the allocation done.</p>
  
  <p>As far as I know,</p>
  
  <p>All local variables whether primitives,pointers or reference variables per function call are on a new stack frame.</p>
  
  <p>and   anything created with new or malloc goes on heap.</p>
  
  <p>I am confused about few things.</p>
  
  <p>Are references/primitives which are members of an object created on heap also stored on heap ?</p>
  
  <p>and what about those local members of a method that are being recursively created in each frame.
  Are they all on stack, If yes then is that stack memory allocated at runtime ?
  also for literals, are they part of the code segment ?
  and what about globals in C, static in C++/Java and static in C .</p>