Table true/false for C Language
I have heard of a table true false for C Language for and && or || is kind of the mathematics one for which they say if true+true=true and false+true=false
I'm just kind of confuse on this and I tried to do the research but couldn't find any of the table
I just wish to have this table for my notes since I will do more in C language
if someone could bring me to the site or resources where they explain about this more
I've edited my original question to make it a note for my own study. Thanks @thiton for the great references and the rest for an awesome answer/resources.
Logical AND (&&)
false && false: false
false && true: false
true && false: false
true && true: true
Logical OR (||)
false || false: false
false || true: true
true || false: true
true || true: true
Logical NOT (!)
!false: true
!true: false
You probably mean a truth table for the boolean operators, which displays the result of the usual boolean operations (&&, ||). This table is not language-specific, but can be found e.g. here.
You're thinking of Boolean algebra.
Truth values can be described using a Boolean algebra. The article also contains tables for and
and or
. This should help you to get started or to get even more confused.
I think You ask for Boolean algebra which describes the output of various operations performed on boolean variables. Just look at the article on Wikipedia.
Are you looking for De Morgans Laws
Hai Ali i think this below link may be usefull for u.
i think it better to google it before posting an question to us
http://www.technologystudent.com/elec1/dig3.htm
I`d like to add to the already good answers:
The symbols '+', '*' and '-' are sometimes used as shorthand in some older textbooks for OR,∨ and AND,∧ and NOT,¬ logical operators in Bool`s algebra. In C/C++ of course we use "and","&&" and "or","||" and "not","!".
Watch out: "true + true" evaluates to 2 in C/C++ via internal representation of true and false as 1 and 0, and the implicit cast to int!
int main ()
{
std::cout << "true - true = " << true - true << std::endl;
// This can be used as signum function:
// "(x > 0) - (x < 0)" evaluates to +1 or -1 for numbers.
std::cout << "true - false = " << true - false << std::endl;
std::cout << "false - true = " << false - true << std::endl;
std::cout << "false - false = " << false - false << std::endl << std::endl;
std::cout << "true + true = " << true + true << std::endl;
std::cout << "true + false = " << true + false << std::endl;
std::cout << "false + true = " << false + true << std::endl;
std::cout << "false + false = " << false + false << std::endl << std::endl;
std::cout << "true * true = " << true * true << std::endl;
std::cout << "true * false = " << true * false << std::endl;
std::cout << "false * true = " << false * true << std::endl;
std::cout << "false * false = " << false * false << std::endl << std::endl;
std::cout << "true / true = " << true / true << std::endl;
// std::cout << true / false << std::endl; ///-Wdiv-by-zero
std::cout << "false / true = " << false / true << std::endl << std::endl;
// std::cout << false / false << std::endl << std::endl; ///-Wdiv-by-zero
std::cout << "(true || true) = " << (true || true) << std::endl;
std::cout << "(true || false) = " << (true || false) << std::endl;
std::cout << "(false || true) = " << (false || true) << std::endl;
std::cout << "(false || false) = " << (false || false) << std::endl << std::endl;
std::cout << "(true && true) = " << (true && true) << std::endl;
std::cout << "(true && false) = " << (true && false) << std::endl;
std::cout << "(false && true) = " << (false && true) << std::endl;
std::cout << "(false && false) = " << (false && false) << std::endl << std::endl;
}
yields :
true - true = 0
true - false = 1
false - true = -1
false - false = 0
true + true = 2
true + false = 1
false + true = 1
false + false = 0
true * true = 1
true * false = 0
false * true = 0
false * false = 0
true / true = 1
false / true = 0
(true || true) = 1
(true || false) = 1
(false || true) = 1
(false || false) = 0
(true && true) = 1
(true && false) = 0
(false && true) = 0
(false && false) = 0