Reputation: 12616
Let's say I've got that:
char *p = NULL;
I'm sure this one would be a problem as I'd be dereferencing a NULL
pointer:
*p = 16;
On the other hand, I think this one would be OK for I'd be getting the address of *p which is not NULL
itself:
char **pp = &p;
Am I right in both cases?
Upvotes: 1
Views: 91
Reputation: 678
You are correct in both cases. Just to add a simple clarification. Though you assign
char **pp = &p;
You still cant access **pp, because it is still has NULL. But you can safely access *pp.
Upvotes: 1
Reputation: 137382
Yes you are. Although the value of p is NULL, it still has a valid address, so you may pass its reference.
Upvotes: 5