0
Difference between && and &
Why do we have two AND operators: & and &&?
2 Answers
+ 13
Check this thread: https://www.sololearn.com/Discuss/271191/?ref=app
+ 1
additional to the above mentioned reference to bitwise operators, probably more often you need these functional differences:
and = && is a logical operator, together with or = || aswell as ! = not.
&&, ||, ! are three logical operators:
for example:
if (int a < int b && int b < int c){} // and condition, needs true true
if (int a < int b || int b < int c){} // or condition, needs only 1 true
if (! (age > 16)) /* not-condition turns condition around, if NOT age is greater than 16, meaning: if age is smaller than 16.
The single & is used with pointers and is the adres-of-operator:
int score = 5;
cout << &score;
//output for example: "0x29fee8"
int var = 50;
int *p;
p = &var;
cout << var;
// outputs 50 (value of var, stored at the adres the pointer is pointing to)