A very important special feature of the stack is that the data stored in the stack can be * * * enjoyed. Suppose we also define:
int a = 3;
int b = 3;
The compiler first processes INTA = 3;; First, it will create a reference with the variable A in the stack, and then find out whether there is a value of 3 in the stack. If it is not found, it will store 3 and point A to 3. Then process int b = 3;; After creating the reference variable of B, because the value of 3 already exists in the stack, B will directly point to 3. In this way, both a and b point to 3 at the same time. At this time, if a = 4;; The compiler will then re-search the stack for a value of 4. If there is no value, it will store 4 and point to 4. If it already exists, point A directly to this address. Therefore, the change of the value of A will not affect the value of B. It should be noted that the * * * enjoyment of this kind of data is different from the * * * enjoyment of two objects referencing one object at the same time, because in this case, the modification of A will not affect B, and it is completed by the compiler, which is conducive to saving space. However, an object reference variable modifies the internal state of this object, which will affect another object reference variable.