Some symbols have multiple meanings

Source: Internet
Author: User

Symbols like * and & can be used as operators in expressions and as part of declarations. The symbol context determines the meaning of symbols.

Int I = 42;

Int & R = I; // & immediately following the type name, so it is part of the declaration and R is a reference

Int * P; // * follows the type name, so it is part of the Declaration, and P is a pointer.

P = & I; // & appears in the expression, which is an address operator.

* P = I; // * is a quote in the expression.

Int & r2 = * P; // & it appears immediately after the type name. Therefore, it is part of the Declaration. R2 is a reference. * It appears in an expression and is a quote.

In declared statements, & and * are used to form a conforming type. In expressions, their roles are converted into operators. In different scenarios, although it is the same symbol, it can be viewed as a different symbol because of its completely different meanings.


Some symbols have multiple meanings

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.