in c++, if we assign a pointer value to NULL
,why dont we check if *p!=NULL
and instead p!=NULL
?
I found this code in a tutorial.
int *p = NULL;
char *q = NULL;
// ...
if (p!=NULL) cout << *p;
Thanks in advance
The *
is doing two different things. When you declare the variable, it means the variable is a pointer. When you use the variable, it means "dereference", that is take the value at the location the pointer is pointing to. Two totally different meanings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With