Assert is commonly known as assert. I personally think it is more accurate to verify the features. Here is its usage.

Source: Internet
Author: User

#include <iostream>   #include <assert.h>     // #define _NDEBUG     #ifndef _NDEBUG       #define _DEBUG   #endif // _DEBUG     using namespace std;    bool TestValue(int a)  {      if ( a > 100 )          return false;      else          return true;  }  int main()  {      int x = 10;      #ifdef _DEBUG       assert( TestValue(x) );      #endif       cout << "Hello world!" << endl;        x = 20;      assert( TestValue(x) );      cout << "New Hello World!" << endl;        x = 120;      #ifdef _DEBUG       assert( TestValue(x) );      #endif       cout << "The last line output!!!" << endl;        return 0;  }  #include <iostream>#include <assert.h>// #define _NDEBUG#ifndef _NDEBUG    #define _DEBUG#endif // _DEBUGusing namespace std;bool TestValue(int a){    if ( a > 100 )        return false;    else        return true;}int main(){    int x = 10;    #ifdef _DEBUG    assert( TestValue(x) );    #endif    cout << "Hello world!" << endl;    x = 20;    assert( TestValue(x) );    cout << "New Hello World!" << endl;    x = 120;    #ifdef _DEBUG    assert( TestValue(x) );    #endif    cout << "The last line output!!!" << endl;    return 0;}

 

// The whole process is very simple, and the idea is clear. You don't need to make comments. You can understand everything after you copy it and run it again.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.