9.7 Null pointers

주홍영·2022년 3월 13일
0

Learncpp.com

목록 보기
98/199

pointer는 null 값을 담을 수 있다
따라서 initialization이 필요하지도 않는 것이다

이때 키워드는 nullptr이다

int* ptr { nullptr };

Dereferencing a null pointer results in undefined behavior

nullptr을 dereference하는 것은 c++ programmer가 가장 많이 crash를 야기시키는 원인이다

Checking for null pointers

우리는 null pointer가 아닌지 확인하기 위해서
다음과 같은 방법을 사용할 수 잇다

if (ptr != nullptr)

or

if (ptr)

만약 ptr이 nullptr이면 두 if 문 모두 실행이 되지 않는다

profile
청룡동거주민

0개의 댓글