First, what is "declaration time"? Some memory is allocated by the loader of you application, some is additionally allocated during run time. It depends on what is your variable. It can be static and allocated by the loaded is some section of memory dedicated to static data. It can be "segment", some pages of pages memory, etc., depending on system architecture. Stack variable is allocated on stack, but the stack itself is allocated when its thread is created, as a phase of loading of application in case of main (starting) thread and during run time for threads created during run time.
Now, about the object of the class allocated on heap… Not just heap is involved: there are two different parts of this object: the variable points to the pointer, and the pointer points to the memory in heap where "object itself" is placed. So, the memory referenced by the pointer is, yes, allocated in heap, but the pointer itself is placed in memory exactly as in the case of integer variables, as described above. But on the top of it, a pointer can be allocated in heap itself. Simple example: a pointer can be a member of other class. And the pointer to the object of that class&hellop; well,
you understand… :-)
—SA