+
) character+=
) charactersint x = 3;
int additionExample1 = 1 + 2;
int additionExample2 = 1 + x;
int additionExample3 = 2;
#include <iostream>
int x = 3;
int additionExample1 = 1 + 2;
int additionExample2 = 1 + x;
int additionExample3 = 2;
int main() {
std::cout << "additionExample1 -> " << additionExample1 << std::endl;
std::cout << "additionExample2 -> " << additionExample2 << std::endl;
std::cout << "additionExample3 += x -> " << (additionExample3 += x) << std::endl;
return 0;
}
additionExample1 -> 3
additionExample2 -> 4
additionExample3 += x -> 5
-
) character-=
) charactersint x = 3;
int subtractionExample1 = 2 - 2;
int subtractionExample2 = x - 1;
int subtractionExample3 = 2;
#include <iostream>
int x = 3;
int subtractionExample1 = 2 - 2;
int subtractionExample2 = x - 1;
int subtractionExample3 = 2;
int main() {
std::cout << "subtractionExample1 -> " << subtractionExample1 << std::endl;
std::cout << "subtractionExample2 -> " << subtractionExample2 << std::endl;
std::cout << "subtractionExample3 -= x -> " << (subtractionExample3 -= x) << std::endl;
return 0;
}
subtractionExample1 -> 0
subtractionExample2 -> 2
subtractionExample3 -= x -> -1
/
) character/=
)
charactersint x = 3;
int divisionExample1 = 9 / 3;
int divisionExample2 = x / 2;
int divisionExample3 = 9;
#include <iostream>
int x = 3;
int divisionExample1 = 9 / 3;
int divisionExample2 = x / 2;
int divisionExample3 = 9;
int main() {
std::cout << "divisionExample1 -> " << divisionExample1 << std::endl;
std::cout << "divisionExample2 -> " << divisionExample2 << std::endl;
std::cout << "divisionExample3 /= x -> " << (divisionExample3 /= x) << std::endl;
return 0;
}
divisionExample1 -> 3
divisionExample2 -> 1
divisionExample3 /= x -> 3
*
) character*=
) charactersint x = 3;
int multiplicationExample1 = 9 * 3;
int multiplicationExample2 = x * 2;
int multiplicationExample3 = 9;
#include <iostream>
int x = 3;
int multiplicationExample1 = 9 * 3;
int multiplicationExample2 = x * 2;
int multiplicationExample3 = 9;
int main() {
std::cout << "multiplicationExample1 -> " << multiplicationExample1 << std::endl;
std::cout << "multiplicationExample2 -> " << multiplicationExample2 << std::endl;
std::cout << "multiplicationExample3 *= x -> " << (multiplicationExample3 *= x) << std::endl;
return 0;
}
multiplicationExample1 -> 27
multiplicationExample2 -> 6
multiplicationExample3 *= x -> 27
%
) character%=
) charactersint x = 8;
int modulusExample1 = 2 % 4;
int modulusExample2 = x % 2;
int modulusExample3 = 3;
#include <iostream>
int x = 8;
int modulusExample1 = 2 % 4;
int modulusExample2 = x % 2;
int modulusExample3 = 3;
int main() {
std::cout << "modulusExample1 -> " << modulusExample1 << std::endl;
std::cout << "modulusExample2 -> " << modulusExample2 << std::endl;
std::cout << "modulusExample3 %= x -> " << (modulusExample3 %= x) << std::endl;
return 0;
}
modulusExample1 -> 2
modulusExample2 -> 0
modulusExample3 %= x -> 3
==
) charactersint x = 3;
int y = 3;
int z = 5;
bool sameAsExample1 = (x == y);
bool sameAsExample2 = (x == z);
#include <iostream>
int x = 3;
int y = 3;
int z = 5;
bool sameAsExample1 = (x == y);
bool sameAsExample2 = (x == z);
int main() {
std::cout << "sameAsExample1 -> " << sameAsExample1 << std::endl;
std::cout << "sameAsExample2 -> " << sameAsExample2 << std::endl;
return 0;
}
sameAsExample1 -> 1
sameAsExample2 -> 0
!=
) charactersint x = 3;
int y = 3;
int z = 5;
bool notEqualExample1 = (x != y);
bool notEqualExample2 = (x != z);
#include <iostream>
int x = 3;
int y = 3;
int z = 5;
bool notEqualExample1 = (x != y);
bool notEqualExample2 = (x != z);
int main() {
std::cout << "notEqualExample1 -> " << notEqualExample1 << std::endl;
std::cout << "notEqualExample2 -> " << notEqualExample2 << std::endl;
return 0;
}
notEqualExample1 -> 0
notEqualExample2 -> 1
>
)
characterint x = 3;
int y = 2;
int z = 1;
bool greaterThanExample1 = (x > y);
bool greaterThanExample2 = (z > x);
#include <iostream>
int x = 3;
int y = 2;
int z = 1;
bool greaterThanExample1 = (x > y);
bool greaterThanExample2 = (z > x);
int main() {
std::cout << "greaterThanExample1 -> " << greaterThanExample1 << std::endl;
std::cout << "greaterThanExample2 -> " << greaterThanExample2 << std::endl;
return 0;
}
greaterThanExample1 -> 1
greaterThanExample2 -> 0
>=
)
charactersint x = 3;
int y = 2;
int z = 3;
bool greaterThanEqualToExample1 = (x >= y);
bool greaterThanEqualToExample2 = (z > x);
bool greaterThanEqualToExample3 = (z >= x);
#include <iostream>
int x = 3;
int y = 2;
int z = 3;
bool greaterThanEqualToExample1 = (x >= y);
bool greaterThanEqualToExample2 = (z > x);
bool greaterThanEqualToExample3 = (z >= x);
int main() {
std::cout << "greaterThanEqualToExample1 -> " << greaterThanEqualToExample1 << std::endl;
std::cout << "greaterThanEqualToExample2 -> " << greaterThanEqualToExample2 << std::endl;
std::cout << "greaterThanEqualToExample3 -> " << greaterThanEqualToExample3 << std::endl;
return 0;
}
greaterThanEqualToExample1 -> 1
greaterThanEqualToExample2 -> 0
greaterThanEqualToExample3 -> 1
<
)
characterint x = 3;
int y = 2;
int z = 1;
bool lessThanEqualToExample1 = (x < y);
bool lessThanEqualToExample2 = (z < x);
#include <iostream>
int x = 3;
int y = 2;
int z = 1;
bool lessThanEqualToExample1 = (x < y);
bool lessThanEqualToExample2 = (z < x);
int main() {
std::cout << "lessThanEqualToExample1 -> " << lessThanEqualToExample1 << std::endl;
std::cout << "lessThanEqualToExample2 -> " << lessThanEqualToExample2 << std::endl;
return 0;
}
lessThanEqualToExample1 -> 0
lessThanEqualToExample2 -> 1
<=
)
charactersint x = 3;
int y = 2;
int z = 3;
bool lessThanEqualToExample1 = (x >= y);
bool lessThanEqualToExample2 = (z > x);
bool lessThanEqualToExample3 = (z >= x);
#include <iostream>
int x = 3;
int y = 2;
int z = 3;
bool lessThanEqualToExample1 = (x >= y);
bool lessThanEqualToExample2 = (z > x);
bool lessThanEqualToExample3 = (z >= x);
int main() {
std::cout << "lessThanEqualToExample1 -> " << lessThanEqualToExample1 << std::endl;
std::cout << "lessThanEqualToExample2 -> " << lessThanEqualToExample2 << std::endl;
std::cout << "lessThanEqualToExample3 -> " << lessThanEqualToExample3 << std::endl;
return 0;
}
lessThanEqualToExample1 -> 1
lessThanEqualToExample2 -> 0
lessThanEqualToExample3 -> 1
true
&&
)
characters for the logical check
true
then
true
is returnedfalse
then false
will be
returnedbool andExample1 = (6 > 5 && 6 < 10);
bool andExample2 = (6 > 7 && 6 < 10);
#include <iostream>
bool andExample1 = (6 > 5 && 6 < 10);
bool andExample2 = (6 > 7 && 6 < 10);
int main() {
std::cout << "andExample1 -> " << andExample1 << std::endl;
std::cout << "andExample2 -> " << andExample2 << std::endl;
return 0;
}
andExample1 -> 1
andExample2 -> 0
or
operator checks whether one of
the comparison operators evaluate to
true
||
) characters for the
logical check
true
then true
is returnedbool orExample1 = (6 > 5 || 6 < 10);
#include <iostream>
bool orExample1 = (6 > 5 || 6 < 10);
int main() {
std::cout << "orExample1 -> " << orExample1 << std::endl;
return 0;
}
orExample1 -> 1
!
) character
for the logical check
true
it
will then be returned as false
and
vice-versabool notExample1 = (6 > 5);
bool notExample2 = !(6 > 5);
#include <iostream>
bool notExample1 = (6 > 5);
bool notExample2 = !(6 > 5);
int main() {
std::cout << "notExample1 -> " << notExample1 << std::endl;
std::cout << "notExample2 -> " << notExample2 << std::endl;
return 0;
}
notExample1 -> 1
notExample2 -> 0
char
and
int
data types&
) character
1
if and only if both of
the operands are 1
0
int binaryAndExample1 = 12;
int binaryAndExample2 = 25;
int binaryAndExample3 = (binaryAndExample1 & binaryAndExample2);
#include <iostream>
#include <bitset>
int binaryAndExample1 = 12;
int binaryAndExample2 = 25;
int binaryAndExample3 = (binaryAndExample1 & binaryAndExample2);
int main() {
std::bitset<8> x(binaryAndExample1);
std::bitset<8> y(binaryAndExample2);
std::bitset<8> z(binaryAndExample3);
std::cout << "binaryAndExample1 -> " << binaryAndExample1 << "\t\tBinary Form: " << x << std::endl;
std::cout << "binaryAndExample2 -> " << binaryAndExample2 << "\t\tBinary Form: " << y << std::endl;
std::cout << "binaryAndExample3 -> " << binaryAndExample3 << "\t\tBinary Form: " << z << std::endl;
return 0;
}
binaryAndExample1 -> 12 Binary Form: 00001100
binaryAndExample2 -> 25 Binary Form: 00011001
binaryAndExample3 -> 8 Binary Form: 00001000
|
) character
1
if at least one of the
operands is 1
0
int binaryOrExample1 = 12;
int binaryOrExample2 = 25;
int binaryOrExample3 = (binaryOrExample1 | binaryOrExample2);
#include <iostream>
#include <bitset>
int binaryOrExample1 = 12;
int binaryOrExample2 = 25;
int binaryOrExample3 = (binaryOrExample1 | binaryOrExample2);
int main() {
std::bitset<8> x(binaryOrExample1);
std::bitset<8> y(binaryOrExample2);
std::bitset<8> z(binaryOrExample3);
std::cout << "binaryOrExample1 -> " << binaryOrExample1 << "\t\tBinary Form: " << x << std::endl;
std::cout << "binaryOrExample2 -> " << binaryOrExample2 << "\t\tBinary Form: " << y << std::endl;
std::cout << "binaryOrExample3 -> " << binaryOrExample3 << "\t\tBinary Form: " << z << std::endl;
return 0;
}
binaryOrExample1 -> 12 Binary Form: 00001100
binaryOrExample2 -> 25 Binary Form: 00011001
binaryOrExample3 -> 29 Binary Form: 00011101
^
) character
1
if and only if one of the
operands is 1
0
, or
both are 1
, it will return
0
int binaryXorExample1 = 12;
int binaryXorExample2 = 25;
int binaryXorExample3 = (binaryXorExample1 ^ binaryXorExample2);
#include <iostream>
#include <bitset>
int binaryXorExample1 = 12;
int binaryXorExample2 = 25;
int binaryXorExample3 = (binaryXorExample1 ^ binaryXorExample2);
int main() {
std::bitset<8> x(binaryXorExample1);
std::bitset<8> y(binaryXorExample2);
std::bitset<8> z(binaryXorExample3);
std::cout << "binaryXorExample1 -> " << binaryXorExample1 << "\t\tBinary Form: " << x << std::endl;
std::cout << "binaryXorExample2 -> " << binaryXorExample2 << "\t\tBinary Form: " << y << std::endl;
std::cout << "binaryXorExample3 -> " << binaryXorExample3 << "\t\tBinary Form: " << z << std::endl;
return 0;
}
binaryXorExample1 -> 12 Binary Form: 00001100
binaryXorExample2 -> 25 Binary Form: 00011001
binaryXorExample3 -> 21 Binary Form: 00010101
~
) character
1
to
0
and 0
to 1
int binaryCompExample1 = 35;
int binaryCompExample2 = ~binaryCompExample1;
#include <iostream>
#include <bitset>
int binaryCompExample1 = 35;
int binaryCompExample2 = ~binaryCompExample1;
int main() {
std::bitset<8> x(binaryCompExample1);
std::bitset<8> y(binaryCompExample2);
std::cout << "binaryCompExample1 -> " << binaryCompExample1 << "\t\tBinary Form: " << x << std::endl;
std::cout << "binaryCompExample2 -> " << binaryCompExample2 << "\t\tBinary Form: " << y << std::endl;
return 0;
}
binaryCompExample1 -> 35 Binary Form: 00100011
binaryCompExample2 -> -36 Binary Form: 11011100
<<
)
character
0
int binaryShiftLeftExample1 = 32;
for (int i = 1; i <= 2; ++i) {
binaryShiftLeftExample1 << i;
}
#include <iostream>
#include <bitset>
int binaryShiftLeftExample1 = 32;
int main() {
std::bitset<8> x(binaryShiftLeftExample1);
std::cout << "binaryShiftLeftExample1 -> " << binaryShiftLeftExample1 << "\t\tBinary Form: " << x << std::endl;
for (int i = 1; i <= 2; ++i) {
std::cout << "Left Shift by " << i << ": " << (binaryShiftLeftExample1 << i) << "\t\t\tBinary Form: " << std::bitset<8>(binaryShiftLeftExample1 << i).to_string() << std::endl;
}
return 0;
}
binaryShiftLeftExample1 -> 32 Binary Form: 00100000
Left Shift by 1: 64 Binary Form: 01000000
Left Shift by 2: 128 Binary Form: 10000000
>>
)
character
0
int binaryShiftRightExample1 = 32;
for (int i = 1; i <= 2; ++i) {
binaryShiftRightExample1 >> i;
}
#include <iostream>
#include <bitset>
int binaryShiftRightExample1 = 32;
int main() {
std::bitset<8> x(binaryShiftRightExample1);
std::cout << "binaryShiftRightExample1 -> " << binaryShiftRightExample1 << "\t\tBinary Form: " << x << std::endl;
for (int i = 1; i <= 2; ++i) {
std::cout << "Right Shift by " << i << ": " << (binaryShiftRightExample1 >> i) << "\t\t\tBinary Form: " << std::bitset<8>(binaryShiftRightExample1 >> i).to_string() << std::endl;
}
return 0;
}
binaryShiftRightExample1 -> 32 Binary Form: 00100000
Right Shift by 1: 16 Binary Form: 00010000
Right Shift by 2: 8 Binary Form: 00001000