Home  >  Article  >  Backend Development  >  What are the differences and similarities between pointers and references?

What are the differences and similarities between pointers and references?

王林
王林Original
2020-04-30 14:22:525382browse

What are the differences and similarities between pointers and references?

1. The similarities between references and pointers

1. Both pointers and references can optimize parameter passing efficiency;

2. Both are concepts of address; the

pointer points to a piece of memory, and its content is the address of the pointed memory; the reference is the alias of a certain piece of memory.

2. The difference between references and pointers

1. Pointers occupy memory space, while references do not occupy memory space;

2. Pointers can be Null, but the reference cannot be null;

3. The pointer does not need to be initialized, but the reference must be initialized;

4. The pointer can have multiple levels, but the reference can only be one level;

5. The value of the pointer can be changed after initialization, that is, it points to other storage units, but the reference will not change after initialization.

6. The pointer is A variable, whereas a reference is just a reference.

If you want to learn more related knowledge, please pay attention to php Chinese website.

The above is the detailed content of What are the differences and similarities between pointers and references?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn