The difference between a reference and a pointer in C + +

Source: Internet
Author: User

1. The main difference between pointers and references.

A reference is another name (a nickname) for a variable, typically the initial value is copied directly to the variable when the variable is initialized, and when the reference is defined, the reference (nickname) and the initial value are "bound" together, rather than copying the initial value to the reference. Because the reference cannot be re-bound to another object, the reference must be initialized. For example: There is a variable called Zhang San, zhang San = 2. Give Zhang San a small name small three, namely small three = Zhang San. The definition reference "small three" must be for an object, once the definition is complete, "small three" can no longer specify other variables, so the nickname, must be initialized (for a name).

The reference itself is not an object, you cannot define a reference reference (a reference is just a nickname, not on the account, not for "nickname", in the nickname)

The pointer itself is an object that allows the pointer to be assigned and copied

An initial value is assigned when the pointer is no longer defined.

The difference between a reference and a pointer in C + +

Related Article

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.