C + + references and symbols "&"

Source: Internet
Author: User

First, & means:

1. Take the address symbol, this time it is used in front of the data, such as int a=&b;

2.c++ also uses & as the reference, if you confirm that the program is standard C and not C + +, then you can exclude the reference. The reference is also used in front of the data, and it is only used when defining and declaring , such as int &othername=name;

int &a=b; Defined when used on the left side of the equals sign, is a reference. "Equivalent to A is an alias of B"

int *a=&b; On the right side of the equals sign, and before the data alone, is the address.

int a= (&B) & 0xFFFF; The first & is the in-memory address for B, the second & is bitwise-and, that is, the low 16 bits of the reserved B address value, and the high 16-bit value is cleared 0 (under 32-bit processor).

In fact, the reference is bound to a variable or constant, and once the binding is immutable, it must be initialized when using a reference, and the non-const reference is not directly bound literal value is a number, can only be bound by a variable .

C + + references and symbols "&"

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.