How memory is managed by Stack and Heap

 +--------------+    +--------------+
| | | |
| | | |
|--------------| | |
b| 10 | | |
|--------------| | |
a| 10 | | |
+--------------+ +--------------+
Stack Heap
 +--------------+    +--------------+
| | | |
| | | |
|--------------| | |
b| 4000 | | |
|--------------| |--------------|
a| 4000 | | Hello World |
+--------------+ +--------------+
Stack Heap
Memory address for value "4000" in Stack area.So, object reference in stack area and value in heap area.

--

--

Computer Engineer, Software Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store