Code/Recipes/Enforce logic with assert

From Polytech Center Barcelona
Jump to: navigation, search
#include <cassert>
#include <iostream>

int main()
{
    // Enforce logic with assert
    std::cout << "Hello" << std::endl;
    assert(true);
    int x = 10;
    assert(x > 0);
    int y = 11;
    // assert that y is an even number
    assert(y % 2 == 0);
    std::cout << "Goodbye" << std::endl;
    return 0;
}