Similarities and differences between pointers and references

Source: Internet
Author: User

Note: assigned ......

 

★Similarities:

● All are addresses;

The Pointer Points to a piece of memory. Its content refers to the memory address, and the reference is the alias of a piece of memory.

★Differences:

● A pointer is an entity, and a reference is only an alias;

● The reference can only be initialized once during definition, but cannot be changed afterwards; the pointer can be changed; the reference can be "from one end", and the pointer can be "Thinking Differently ";

● Reference has no const, pointer has const, and const pointer is immutable; (specifically, there is no Int & Const A, while const Int & A has, the former guidance itself means that the alias cannot be changed. This is of course, so this form is not required. The value indicated by the latter guidance cannot be changed)

● The reference cannot be blank or the pointer can be blank;

● "Sizeof reference" gets the size of the variable (object) pointed to, while "sizeof Pointer" gets the size of the pointer;

● Pointer and reference auto-increment (++) operations have different meanings;

● The reference is type-safe, but the pointer is not (the reference has more type checks than the pointer

Similarities and differences between pointers and references

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.