引用和指针的区别 Difference between pointer and reference

时间:2021-08-29 13:28:03

1. 引用必须初始化,而指针不用;

2. 引用一旦初始化便不可以指向其他对象,而指针可以;

3. 引用不能指向NULL,而指针可以;

4. 动态分配的内存必须由指针指向,而不能有引用指向;

5. 指针可以进行增减运算,并且适用于任何指针算术操作,而引用不行。

1. Reference should be initialized and pointer need not be.

2. Reference can’t be changed to some other objects it is once initialized but pointer can be.

3. The dynamic allocated memory can only be pointed to by a pointer.

4. Reference can’t point to NULL and pointer can.

5. Pointer can be incremented or decremented and subjected to any pointer arithmetic operations, but reference can’t.