C ++ reference

Source: Internet
Author: User

C ++ references

References in C ++ can be seen as another way of talking about the variable name, as well as the external number of the variable, another name, Value Method &

Int A = 100;

Int & aa = A; // defines an int-type application, which is a reference to variable.

Here, a and AA point to the same address in the memory, that is, they point to the same memory and store the same data.

 

An application is like a woman in ancient China. Once she is married to someone, she will spend the rest of her life. Therefore, if you define an alias for a variable, it will always belong to this variable, it will faithfully follow this variable, even if there are other variables in the middle to buy him, he will not change his master, but he will buy his money, as a result, his master is also affected.

Therefore, an application can also be seen as an alias constant.

When we try to assign a value to an alias, we can only change the value of another storage, but we cannot change the memory address pointed to by the alias,

 

 

 

The end!

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: info-contact@alibabacloud.com 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.