断言(0)是什么意思?

编程入门 行业动态 更新时间:2024-10-23 17:30:08
本文介绍了断言(0)是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在一次考试中遇到了这样的问题,但我仍然不太确定如何回答.我知道断言是测试程序的方法,但是我不太确定 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)是什么意思?

本文发布于:2023-10-04 11:07:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1467155.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:断言

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!