Search code examples
c++nullptr

Where are these nullptr located?


int* x = nullptr;
class_example* obj = nullptr;

I understand what nullprt is, but where are these variables x and obj located?

Heap? or Stack?


Solution

  • Pointers are just ordinary variables, that happen to have values that are addresses of other objects (and those addresses could be on the heap).

    So in this snippet:

    int main() 
    {
      int* x = nullptr;
      class_example* obj = nullptr;
    }
    

    just like regular local variables, these pointers will be located on the stack.