assert(0)是什么意思? [英] What does assert(0) mean?

查看:374
本文介绍了assert(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.

推荐答案

它将始终失败.就是这样.由于x等于5时"assert(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);
 }

这篇关于assert(0)是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆