Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

There are several main types of references

Shulou Source: shulou.com Published: 2022-06-03 02:29:43 09月30日 Update

What are the main types of references? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Reference type A data type represented by a reference to the actual value of the type (similar to a pointer). If you assign a reference type to a variable, the variable references (or "points to") the original value. No copies are created. Reference types include class, interface, delegate, and boxing value types.

"reference" is a new variable type of C++ and an important supplement to C. Its function is to give an alias to the variable. If you have a variable an and you want to give it an alias, you can write:

Int a Ting int & Bauda

This indicates that b is the "reference" of a, that is, the alias of a. After such a declaration, using an or b has the same effect and represents the same variable. In the above reference, & is a "reference declarant" and does not represent an address.

Don't interpret it as "assign the value of a to the address of b". The data of the reference type is stored in the heap of memory, and only the address of the object in the heap is stored in the memory unit. Declaring references does not open up memory units; b and a both represent the same variable unit.

Note: when declaring a reference variable type, you must also initialize it, that is, declare which variable it represents. After declaring a reference to a variable, the reference is associated with the variable it represents during the execution of this function

Can no longer be used as aliases for other variables The following usage is incorrect:

Int a1,a2

Int & b=a1

It is not possible for int & bauxa2hopping / to try to make b an alias for a2. This is wrong.

We can assign the value of a2 to b.

B=a2

This is the end of the answer to several main questions about citation types. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Tags: Variables types representations aliases memory units addresses questions functions data more help solutions no no original easy same important simple Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS NVidia OPPO Reno Shulou Tech Info Linux