开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜