xxxxxxxxxx
// | is the binary "or" operator
// a |= b is equivalent to a = a|b
#include <stdio.h>
int main() {
int a = 10; // 00001010 in binary
int b = 6; // 00000110 in binary
printf("Result : %d\n", a |= b);
// Result is 14 which is OOOO111O in binary
return 0;
}
xxxxxxxxxx
/*
* The << operator shifts the bits of an integer a certan amount of steps to the left
* So a << n means shifting the bits of a to the left n times
*/
#include <stdio.h>
int main() {
int a = 10; // 00001010 in binary
int n = 2;
printf("Result : %d\n", a << n);
// Result is 40 which is OO101000 in binary
return 0;
}
// This also means that a << n is an equivalent to a * 2^n
xxxxxxxxxx
/* The expression a ? b : c evaluates to b if the value of a is true,
* and otherwise to c
*/
// These tests are equivalent :
if (a > b) {
result = x;
}
else {
result = y;
}
// and
result = a > b ? x : y;
xxxxxxxxxx
? : Conditional Expression operator
If Condition is true ? then value X : otherwise value Y
y = x==0 ? 0 : y/x
xxxxxxxxxx
The logical AND operator is represented as the '&&' double ampersand symbol in c.