Clouds
Home
Tutorial of C language
Computer Language
Introduction to C
Programming in C
Structure of C program
Variable in C
Datatypes in C
Token in C
Operator in C
Precedence of C Operator
Assignment Operator in C
Logical Operator in C
Bitwise Operator in C
Ternary Operator in C
C Input Output
Pointers in C
Storage Classes of C
Control Structure of C
C Decision Making Statement
C Looping Statement
C Jumping Statement
C Function
Function Call By Value
Function Call By Reference
C Input Output Function
C Structure
Array in C
Union in C

Logical Operator

  • An expression that combines two or more expressions is termed as a logical expression. For combining these expressions we use the logical operator.
  • After testing the value of the condition [which is True (1) or False (0)]. It gives the logical status (True or False) as an overall result.
    Operator Meaning
    && Logical AND
    || Logical OR
    ! Logical NOT

    AND (&&) Operator:

    This operator gives the net result true if the condition or expression have the value true(1), otherwise gives the net result false.
  • Example1:-
    Let x=20 and y=10
    The logical expression is
    (x==20) && (x>y)
    This gives the result true because both the condition (x==20) and (x>y) are true and gives the net result true.
  • Example2:-
    Let x=10 and y=20
    The logical expression is
    (x==10) && (x>y)
    This gives the result false because the condition (x==20) is true but the condition(x>y) is false and gives the net result false.

    OR ( || ) Operator:

    This operator gives the net result false, if both the conditions have the value false, otherwise it gives the net result true.
  • Example1:-
    Let x=10 and y=20
    The logical expression is
    (x>=y) || (x>20)
    This gives the result false because both the conditions are false and gives the net result false.
  • Example2:-
    Let x=10 and y=20
    The logical expression is
    (x>=y) || (y>10)
    This gives the result true because one condition is true and thus gives the net result true.

    NOT ( ! ) Operator:

  • This is unary operator.
  • If the value of the condition is true then it gives the result false.
  • If the value of the condition is false then it gives the result true.
    Example:-
    Let x=10
    The logical expression is
    !(x>5)
    Here the condition (x>5) is true. NOT operator negates the value of the condition.
    Hence the result is false.
    Bitwise Operator in C >>
    Ternary Operator in C >>
    C Input Output >>
    Pointers in C >>
    Storage Classes of C >>


    Home Clouds