我在一次考试中遇到了这样的问题,但我仍然不太确定如何回答.我知道断言是测试程序的方法,但是我不太确定 assert(0) 正在检查什么.这是一个技巧问题吗?它总是会失败,但我不明白为什么.它在检查什么?
I had a question like this on one of my exams and I'm still not too sure how to answer it. I understand that assertions are ways to test your program, however I'm not too sure what assert(0) is checking. Is this a trick question? It will always fail, but I don't understand why. What is it checking?
任何解释都会很棒,谢谢.
Any explanation would be great, thanks.
推荐答案它总是会失败.差不多就是这样.它总是会失败,原因与assert(x == 5)"在 x = 5 时会成功的原因相同.
It will always fail. That's pretty much it. It will fail always for the same reason that "assert(x == 5)" will succeed whenever x = 5.
如果您要求一个应用程序,那么您会将它放在真正不应该发生的代码块中.
If you're asking for an application then you would put it in code blocks that really shouldn't happen.
switch(suit) { case CLUB: case DIAMOND: case HEART: case SPADE: // ... default: assert(0); }更多推荐
断言(0)是什么意思?
发布评论