/////////////////////////////////////////////////////////////// // exmp2e.cpp - C++ Memory Model // // // // Jim Fawcett, ELE591\791, Su'99 // // // // build: cl /GX exmp1e.cpp // /////////////////////////////////////////////////////////////// #include #include using namespace std; string s0 = "\n string s0 is a global variable and is created in static memory"; void function1() { string s2 = "\n string s2 is created in function1()'s stack frame"; s2 += "\n - this is an addition"; cout << s2 << endl; static string s3 = "\n string s3 is created in static memory"; s3 += "\n - this is an addition"; cout << s3 << endl; } void main() { cout << "\n Demonstrating C++ Memory Model " << "\n ================================\n\n"; cout << s0 << endl; string s1 = "\n string s1 is created in main()'s stack frame"; cout << s1 << endl; function1(); function1(); string *pStr = new string("\n string s4 is created on the heap"); cout << *pStr << "\n\n"; delete pStr; }