// mem.cpp - memory demo for cs32 // cmc, 11/20/2017 #include using namespace std; int global; // object stored in the global data space int main() // main function's code stored too { // when main executes, it's data are stored on the stack int local; // local object int *heap = new int; // local pointer to heap object // print address of start of main function code int *start = (int *)&main; cout << "main @ " << start << endl; // print addresses of other objects (and differences // from the start of main) cout << "global @ " << &global << " (" << &global - start << " from main)\n"; cout << "heap @ " << heap << " (" << heap - start << " from main)\n"; cout << "local @ " << &local << " (" << &local - start << " from main)\n"; return 0; }