&& and the ||

I'd love if someone can explain to me what does the && do and what does the || do as well.
&& 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.



@AbstractionAnon Can you like give me example codes? Would make it easier to understand
Did you read the page i linked?
There are examples there along with truth tables for both operators.
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
closed account (E0p9LyTq)
http://en.cppreference.com/w/cpp/language/operator_logical
closed account (E0p9LyTq)
Also, see http://www.learncpp.com/cpp-tutorial/36-logical-operators/
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
Topic archived. No new replies allowed.