It depends. The following sample will list the addresses of the objects and the member variables, showing where they are created:
class CObject
{
public:
void Method()
{
printf("\n\tIn Method\n");
int localVar; localVar = 5;
printf("\t\tlocalVar: %p\n", &localVar);
int* heapVar = new int[20]; heapVar[1] = 100;
printf("\t\theapVar: %p\n", heapVar);
}
};
int result = 0;
printf("result: %p\n", &result);
CObject localObject; printf("\nlocalObject: %p\n", &localObject);
localObject.Method();
CObject* heapObject = new CObject(); printf("\nheapObject: %p\n", heapObject);
heapObject->Method();
You should see the difference (in both cases) between the local variable created in
Method
, and the heap variable.