On the heap

When the following C++ code is run

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include <iostream>
using namespace std;

int main() {
    int x;
    int *y = new int;

    std::cout << x << std::endl;
    std::cout << &x << std::endl;
    std::cout << y << std::endl;
    std::cout << &y << std::endl;
    std::cout << *y << std::endl;

    return 0;
}

I got the following output:

1
2
3
4
5
-1076683684
0xbfd31b98
0x8a5ea10
0xbfd31b9c
0

Which line in the output definitely refers to a location on the heap ?

5 1 3 2 4

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Md Ashiqur Rahman
Jul 28, 2016

new oparetor provides memory from heap stored in computer, which is stored in pointer y.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...