Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- using namespace std;
- int * f_stack(){
- int a[5] = {};
- return a;
- }
- int * f_heap(){
- //int b[5] = {0};
- //int * a = b;
- int * a = new int[5];
- return a;
- }
- int main(int argc, char** argv) {
- //int * b_stack = f_stack();
- int b_stack[5] = {0};
- int * b_heap = f_heap();
- int * c = b_heap;
- b_heap[0] = 10;
- cout << "AddressMem stack: " << b_stack << endl;
- cout << "AddressMem heap: " << b_heap << ":" <<*(b_heap+3)<< endl;
- delete [] b_heap;
- cout << "AddressMem heap (delete): " << b_heap << ":" <<(int)(*b_heap)<< endl;
- b_heap = new int[10];
- cout << "AddressMem heap (new): " << b_heap << ":" <<*b_heap<< endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement