+ 3

why are the values stored in heap and pointers in stack ?

2nd Aug 2016, 11:25 AM
chaitanya
1 Answer
+ 1
Hi chaitanya, it's because the new operator returns the pointer to the heap memory allocated and usually programmers assign this returned pointer to a local, static or global variable. You could also assign it to a pointer in the heap but still you would need a pointer in your local context in order to access it.
2nd Aug 2016, 10:35 PM
Stefan
Stefan - avatar