bool is short for boolean, and is a data type that has two values - true and false. If a boolean value is not true, then it is false.
Let's say we're writing a function that accepts an int argument, and the "certain condition" being tested is for that argument to be equal to 2. Then one way of doing it is;
Code:
bool test_A(int x)
{
if (x == 2)
return true;
else
return false;
}
This can be simplified to ....
Code:
bool test_B(int x)
{
if (x == 2)
return true;
return false;
}
(i.e. the else clause is eliminated) since the only way to return false is if x is not equal to 2. (Note this should not necessarily be done for functions that need to do other work before returning.
Now, the thing is, x == 2 is also a boolean test (it yields true or false, depending on the value of x). So this code can be simplified even further
Code:
bool test_C(int x)
{
return (x == 2) ? true : false;
}
or even to
Code:
bool test_D(int x)
{
return (x == 2);
}