Would these C-pointer operations cause problems?
Let's say I've got that:
char *p = NULL;
I'm sure this one would b开发者_运维知识库e 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?
Yes you are. Although the value of p is NULL, it still has a valid address, so you may pass its reference.
Yes, you are correct in both cases.
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.
精彩评论