Things you don't know about C + + pointers and references "What the hell"?

Source: Internet
Author: User

The pointer , simply put, is to store the address value in a variable, then the variable is a pointer, the reference is to the memory address an alias, of course, the memory address has been taken by the name.

pointer size , which is related to the number of address lines of the machine, and also to the operating system; For example, if your machine is a 64-bit machine, but your system is a 32-bit system, then your pointer variable size should be 4byte? Not verified, just conjecture, have classmates verified, welcome to discuss.

reference size , which is related to the variable it refers to, you actually use the reference as a normal variable, except that the reference variable and another variable are the same memory name.

Difference:

pointers, which can be modified, that is, a pointer variable inside the stored pointer address can be modified to other address values. and the reference in the initialization of the reference to another piece of memory, and then can not change, this can not be changed to refer to the reference to another piece of memory, you in the program to try this change to know why do not.

Const int* A; A constant pointer indicating that the pointer points to a constant address, and that the value of the memory space pointed to by the pointer cannot be modified.

int* const B; The pointer constant indicates that the pointer variable cannot be modified, that is, you cannot reassign the pointer variable. Oh, you can't let him point to another memory address.

const int& C; Constant reference, this alias is given to a constant memory block obtained oh, you can not change the contents of this memory block OH.

int& const D; Reference constant, this itself does not exist oh, in the program so write through not compile OH. Because the reference itself is the alias of another piece of memory, and can not do that oh.

That's it, it's a little bit more than someone else has written a whole bunch of it.


Things you don't know about C + + pointers and references "What the hell"?

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.