&& and the ||

Nov 7, 2015 at 6:34pm
I'd love if someone can explain to me what does the && do and what does the || do as well.
Nov 7, 2015 at 6:56pm
&& is the AND operator.
<bool-expr1> && <bool-expr2>
returns the boolean result of ANDing the two boolean expressions.

|| is the OR operator.
<bool-expr1> || <bool-expr2>
returns the boolean result of ORing the two boolean expressions.

http://www.cplusplus.com/doc/tutorial/operators/
See Logical Operators about half way down.



Nov 7, 2015 at 7:11pm
@AbstractionAnon Can you like give me example codes? Would make it easier to understand
Nov 7, 2015 at 7:18pm
Did you read the page i linked?
There are examples there along with truth tables for both operators.
Nov 7, 2015 at 7:54pm
Yeah I did, I want like i don't know how to explain them like um basic examples? of what would they do and what would happen because I still havent understood from the page either, Sorry if I'm being too much of effort to you :S
Nov 7, 2015 at 8:23pm
closed account (E0p9LyTq)
http://en.cppreference.com/w/cpp/language/operator_logical
Nov 7, 2015 at 8:25pm
closed account (E0p9LyTq)
Also, see http://www.learncpp.com/cpp-tutorial/36-logical-operators/
Nov 7, 2015 at 8:36pm
Basically
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

int main()
{
	bool b1 = true, b2 = false;

	if (b1 && b2)
		std::cout << "Both bools are true" << std::endl;

	if (b1 || b2)
		std::cout << "At least one of the 2 bools is true" << std::endl;
}

The output would be "At least one of the 2 bools is true" because both booleans are not true, look at the table that AbstractionAnon has linked.
Last edited on Nov 7, 2015 at 8:38pm
Topic archived. No new replies allowed.