Value types and reference types

Source: Internet
Author: User

the memory is divided into two main spaces: stack space and heap space. They are all used to store data. Different types of data are stored in different places. One, value types and reference types are divided by: they are stored in memory in different structures. value type: all numeric types, char, bool, enum, struct Reference type:string array class third, local variables and member variables:3.1. Local variables:The same point: Whether a local variable is a value type or a reference type, the local variable is always opened in the stack space.difference: The real value of a value type variable is stored directly in the variable in the stack space.A variable of a reference type that is stored in the heap space and stored in a variable in the stack space is the address of the object in the heap space.3.2. member variables:the member variable is in addition to the object. Whether this member variable is a value type or a reference type, it is opened in the heap space along with the object. This member variable stores values in the same principle as local variables.   iv. Effects of reciprocal assignment between variablesno matter what type of variable is assigned to each other. Copy the value from the source variable and assign the copy to the target variable. The difference is:value type: Because the value type of the variable is stored in the real value, so the copy passed is also the true value. When the assignment is complete, modifications to one variable do not affect the value of the other 1 variables. reference type: Because the object's address is stored in a variable of the reference type, the copy is also passed the address. When the assignment is complete, two variables point to the same object. Modifications to 1 variables have an effect on the other variables.

Value types and reference types

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.