Pointer & Reference

어떠한 대상을 가리킨다는 점에서는 같지만 여러가지 차이점이 있다.

 

1.Null 허용여부

Pointer - NULL 허용

Reference - NULL 제한

 

2.참조대상 할당 및 접근

Pointer - 주소값을 할당

Reference - 참조 대상을 그대로 할당 (선언과 동시에 초기화 해야 한다.)

 

Use references when you can, and pointers when you have to
사용할 수 있다면 참조자를, 어쩔 수 없다면 포인터를 써라

참고 : https://gracefulprograming.tistory.com/11 [Peter의 우아한 프로그래밍]

+ Recent posts