Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've updated your annotations with what I believe is more correct. Note that Tomalak is correct that 'stack' and 'heap' are not specified by the standard, and mechanisms other than a stack might be used to pass parameters to store automatic variables.</p> <p>However, I still use those terms because they are actually used quite often in compiler implementations, the terms are more or less well-understood (or easy to understand), and I think they still pragmatically illustrate what you're interested in knowing.</p> <pre><code>class Foobar { int n; //Stored wherever the current object is stored // (might be static memory, stack or heap depending // on how the object is allocated) public: int pubVar; //Stored wherever the current object is stored // (might be static memory, stack or heap depending // on how the object is allocated) void foo(int param) //param stored in stack or register { int *pp = new int; //int is allocated on heap. n = param; static int nStat; //Stored in static area of memory int nLoc; //stored in stack or register string str = "mystring"; // `str` is stored in stack, however // the string object may also use heap // to manage its data .. if(CONDITION) { static int nSIf; //stored in static area of memory int loopvar; //stored in stack or register .. } } } int main(int) { Foobar bar; //bar stored in stack Foobar *pBar; //pBar is stored in stack pBar = new Foobar(); //the object is created in heap. // The non-static data members are stored in that // memory block. } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload