Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

There are several main types of references

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report