Why should I use asserts?

后端 未结 19 2031
遇见更好的自我
遇见更好的自我 2020-12-12 13:47

I never got the idea of asserts -- why should you ever use them?

I mean, let\'s say I were a formula driver and all the asserts were things like security belt, helm

19条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-12 14:34

    For other answers to this question

    assert() macro is used to test the conditions or assumptions that should not occur in a program. For example, the array index should always be > 0. Another assumption can be 2+2 == 3+1.

    So using assert () we can test such assumptions and as long as they evaluate to true, our program runs normally. When they are false, the program is terminated.

    more here https://www.softwaretestinghelp.com/assert-in-cpp/

提交回复
热议问题