G
G
greedile2021-11-03 11:42:00
C++ / C#
greedile, 2021-11-03 11:42:00

How to work with Heap and Stack?

When we change a reference from a heap (working with variables of a reference type) are we changing the file on the stack or changing the created instance?
Tell me more about this topic in this light.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2021-11-03
@greedile

1. The values ​​of local variables are stored on the stack
2. The values ​​of reference
types are stored on the heap 3. Reference type variables store references to values ​​in the heap
So when you assign a new value to a variable, like this:

object obj = new object();
obj = null;

You do not change the value in the heap, but simply change one reference to another in the variable, and the original object remains untouched

A
Artyom Tokarevsky, 2021-11-03
@artemt

Kind of a dumb question. Roofing felts about working with memory, roofing felts about data structures. You can first look at Link Types and Value Types , if I understand the question correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question