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