Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercise2.23 there might be a mistake here #47

Open
Zhangxh251 opened this issue Apr 17, 2022 · 1 comment
Open

Exercise2.23 there might be a mistake here #47

Zhangxh251 opened this issue Apr 17, 2022 · 1 comment

Comments

@Zhangxh251
Copy link

原题:给定指针 p,你能知道它是否指向了一个合法的对象吗?如果能,叙述判断的思路;如果不能,也请说明原因。

我的看法: 把 if(p) 放在 try 中 , 当程序块顺利执行时,表示p指向了合法的对象;当程序块出错跳转到catch语句时,表示p没有指向合法的对象。

答案思路来源- 牛客网
https://m.nowcoder.com/questionTerminal?uuid=3c218c5306324eaf9de45a74932f0b9e

@likaisoft
Copy link

这个解法应该是有前提:指针初始化为NULL/0,否则if(p)其实等价于 if (p!=0),并不能判断是否指向合法对象。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants