returning multiple boolean functions

closed account (E3h7X9L8)
Can someone explain me this piece of code , the function isSafe is supposed to check the other three functions if they are false or true , if one is false isSafe must return false, I dont really understand whats happening if 2 functions are true and false and whats the purpose of "!" operator.

1
2
3
4
5
6
bool isSafe()
{
    return !checkRow() &&
           !checkCol() &&
           !checkBox();          
}
whats the purpose of "!" operator.
It's logical not, your code is absolutely equivalent to this one:
1
2
3
4
5
6
bool isSafe()
{
    return not checkRow() &&
           not checkCol() &&
           not checkBox();          
}


I dont really understand whats happening if 2 functions are true and false
Maybe you need to learn more about logic operators?
http://www.learncpp.com/cpp-tutorial/36-logical-operators/
your code...

1
2
3
4
bool isSafe()
{
    return !checkRow() && !checkCol() && !checkBox();          
}


The truth table for your function is

1
2
3
4
5
6
7
8
9
a | b | c | ¬a&&¬b&&¬c
T | T | T | F
T | T | F | F
T | F | T | F
T | F | F | F
F | T | T | F
F | T | F | F
F | F | T | F
F | F | F | T



and the above table should show how your function evaluates on each condtion being true or false.

in English...

1
2
3
bool isSafe()
{
    return not (checkrow) and not (checkcol) and not (checkbox)



Last edited on
closed account (E3h7X9L8)
thanks for help guys , i understand now
Topic archived. No new replies allowed.