What does && do?

What does && do in this x = 10, y = 15, and z = 20. (x != 5) && (y != z)
Means both conditions must evaluate to true.

If neither are true or only one is true, then the && is not met and will evaluate to false.
An example...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

using namespace std;

int main()
{
 int a = 1, b = 2, c = 3;
 
 if(a < 1 && b == 2) {
     cout << "a is less than 1 and b is equal to 2";
 }
 
 if(b > 1 && c !=3) {
  cout << "b is greater than 1 and c does not equal 3";   
 }
 
 if(a==1 && c < 5) {
  cout << "a is equal to 1 and c is less than 5";   
 }
 
 
 cin.get();
 return 0;
}
Topic archived. No new replies allowed.