KEMBAR78
Logical Operators C/C++ language Programming | PPTX
Muhammad Shahbaz
Shabbir
NAWAB DEVELOPERS
An operator is a symbol that tells the
compiler to perform specific
mathematical or logical functions.
Example:-
|| , ! , && , + , = etc.
Types
•Arithmetic
•Relational <, >, <=, >=, = , !=
•Logical NOT, AND, OR
•Assignment = , +=, -=, *=, /= , %=
•Auto Increment / Decrement (or unary) --,
++
•Conditional ?:
•Comma ,
•Size of
•Bitwise
Operato
r
Description Exampl
e
&& Called Logical AND operator. If both the operands
are non-zero, then the condition becomes true.
(A && B)
is false.
|| Called Logical OR Operator. If any of the two
operands is non-zero, then the condition becomes
true.
(A || B)
is true.
! Called Logical NOT Operator. It is used to reverse
the logical state of its operand. If a condition is true,
then Logical NOT operator will make it false.
!(A &&
B) is
true.
A B AN
D
OR
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 1
A NOT
0 1
1 0
And &&
Or ||
Not !
Operato
r
Description Example
+ Adds two operands. A + B = 30
− Subtracts second operand from the first. A − B = -10
* Multiplies both operands. A * B = 200
/ Divides numerator by de-numerator. B / A = 2
% Modulus Operator and remainder of after
an integer division.
B % A = 0
++ Increment operator increases the integer
value by one.
A++ = 11
-- Decrement operator decreases the integer
value by one.
A-- = 9
•Rules of operator
precedence
• Operators in parentheses evaluated first
• Multiplication, division, modulus applied
next
• Addition, subtraction applied in last
• Operators applied from left to right
Operato
r
Description Example
== Checks if the values of two operands are
equal or not. If yes, then the condition
becomes true.
(A == B) is not true.
!= Checks if the values of two operands are
equal or not. If the values are not equal, then
the condition becomes true.
(A != B) is true.
> Checks if the value of left operand is greater
than the value of right operand. If yes, then
the condition becomes true.
(A > B) is not true.
< Checks if the value of left operand is less than
the value of right operand. If yes, then the
condition becomes true.
(A < B) is true.
>= Checks if the value of left operand is greater
than or equal to the value of right operand. If
yes, then the condition becomes true.
(A >= B) is not true.
<= Checks if the value of left operand is less than
or equal to the value of right operand. If yes,
(A <= B) is true.
Operato
r
Description Example
= Simple assignment operator. Assigns values
from right side operands to left side operand
C = A + B will assign the
value of A + B to C
+= Add AND assignment operator. It adds the
right operand to the left operand and assign
the result to the left operand.
C += A is equivalent to
C = C + A
-= Subtract AND assignment operator. It
subtracts the right operand from the left
operand and assigns the result to the left
operand.
C -= A is equivalent to C
= C - A
*= Multiply AND assignment operator. It
multiplies the right operand with the left
operand and assigns the result to the left
operand.
C *= A is equivalent to C
= C * A
/= Divide AND assignment operator. It divides
the left operand with the right operand and
assigns the result to the left operand.
C /= A is equivalent to C
= C / A
%= Modulus AND assignment operator. It
takes modulus using two operands and
assigns the result to the left operand.
C %= A is equivalent
to C = C % A
<<= Left shift AND assignment operator. C <<= 2 is same as C
= C << 2
>>= Right shift AND assignment operator. C >>= 2 is same as C
= C >> 2
&= Bitwise AND assignment operator. C &= 2 is same as C
= C & 2
^= Bitwise exclusive OR and assignment
operator.
C ^= 2 is same as C =
C ^ 2
|= Bitwise inclusive OR and assignment
operator.
C |= 2 is same as C =
C | 2
MUHAMMAD SHAHBAZ
SHABBIR AHMAD
C.E.O at NAWAB
DEVELOPERS

Logical Operators C/C++ language Programming

  • 1.
  • 2.
    An operator isa symbol that tells the compiler to perform specific mathematical or logical functions. Example:- || , ! , && , + , = etc.
  • 3.
    Types •Arithmetic •Relational <, >,<=, >=, = , != •Logical NOT, AND, OR •Assignment = , +=, -=, *=, /= , %= •Auto Increment / Decrement (or unary) --, ++ •Conditional ?: •Comma , •Size of •Bitwise
  • 4.
    Operato r Description Exampl e && CalledLogical AND operator. If both the operands are non-zero, then the condition becomes true. (A && B) is false. || Called Logical OR Operator. If any of the two operands is non-zero, then the condition becomes true. (A || B) is true. ! Called Logical NOT Operator. It is used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make it false. !(A && B) is true.
  • 5.
    A B AN D OR 00 0 0 0 1 0 1 1 0 0 1 1 1 1 1 A NOT 0 1 1 0 And && Or || Not !
  • 6.
    Operato r Description Example + Addstwo operands. A + B = 30 − Subtracts second operand from the first. A − B = -10 * Multiplies both operands. A * B = 200 / Divides numerator by de-numerator. B / A = 2 % Modulus Operator and remainder of after an integer division. B % A = 0 ++ Increment operator increases the integer value by one. A++ = 11 -- Decrement operator decreases the integer value by one. A-- = 9
  • 7.
    •Rules of operator precedence •Operators in parentheses evaluated first • Multiplication, division, modulus applied next • Addition, subtraction applied in last • Operators applied from left to right
  • 8.
    Operato r Description Example == Checksif the values of two operands are equal or not. If yes, then the condition becomes true. (A == B) is not true. != Checks if the values of two operands are equal or not. If the values are not equal, then the condition becomes true. (A != B) is true. > Checks if the value of left operand is greater than the value of right operand. If yes, then the condition becomes true. (A > B) is not true. < Checks if the value of left operand is less than the value of right operand. If yes, then the condition becomes true. (A < B) is true. >= Checks if the value of left operand is greater than or equal to the value of right operand. If yes, then the condition becomes true. (A >= B) is not true. <= Checks if the value of left operand is less than or equal to the value of right operand. If yes, (A <= B) is true.
  • 9.
    Operato r Description Example = Simpleassignment operator. Assigns values from right side operands to left side operand C = A + B will assign the value of A + B to C += Add AND assignment operator. It adds the right operand to the left operand and assign the result to the left operand. C += A is equivalent to C = C + A -= Subtract AND assignment operator. It subtracts the right operand from the left operand and assigns the result to the left operand. C -= A is equivalent to C = C - A *= Multiply AND assignment operator. It multiplies the right operand with the left operand and assigns the result to the left operand. C *= A is equivalent to C = C * A /= Divide AND assignment operator. It divides the left operand with the right operand and assigns the result to the left operand. C /= A is equivalent to C = C / A
  • 10.
    %= Modulus ANDassignment operator. It takes modulus using two operands and assigns the result to the left operand. C %= A is equivalent to C = C % A <<= Left shift AND assignment operator. C <<= 2 is same as C = C << 2 >>= Right shift AND assignment operator. C >>= 2 is same as C = C >> 2 &= Bitwise AND assignment operator. C &= 2 is same as C = C & 2 ^= Bitwise exclusive OR and assignment operator. C ^= 2 is same as C = C ^ 2 |= Bitwise inclusive OR and assignment operator. C |= 2 is same as C = C | 2
  • 11.