Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between these two statements? - C++

I'm a programming student trying to better understand pointers, one of the things I learned is that you can set a pointer to NULL. My question is, what's the difference between these two statements? When would each of them return true/false?

if (some_ptr ==  NULL)

if (*some_ptr == NULL)

Thanks!

like image 527
Alex Avatar asked Dec 10 '22 17:12

Alex


1 Answers

The first does a comparison against the address of the variable to null, the second dereferences the pointer, getting the value held at it and compares it against null.

like image 85
mr-sk Avatar answered Dec 18 '22 05:12

mr-sk