Talking about pointers and references

Source: Internet
Author: User
Tags define function

We know that when you use pointers and references to define function parameters, you can change the values of the parameters directly. So what are the differences between pointers and references?

We start with the definition of a reference and a pointer: the reference is the alias of a variable or object, and the pointer stores a machine code address, which is the address of a specific variable or object. So the difference is:

1) The pointer can be empty , but the reference does not

2) The declaration pointer can not point to any object, so you must do a null operation before using the pointer , and the reference does not have to

3) Once the reference is declared, it cannot be changed , but the pointer can, like the + + operator, point to the next object, and the reference changes the contents of the object.

4) The size of the reference is the size of the variable, and the pointer is only a machine code, the size of the pointer is always 4 bytes, regardless of the number of pointers

5) Good reference form

6) The reference is safer than the pointer , and the pointer is very flexible, easy to produce a wild pointer, such as multiple pointers to a piece of memory, free off one, the other pointer is a wild pointer.



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Talking about 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.