LOGICAL OPERATORS IN C

Maha



Logical Operators In C

In C programming, the logical programming are used to perform logical operations like a boolean values that are either true or false. The three logical operators are:  

Logical Operators Are:

&&  logical AND : Returns true if both operands are true.

||      logical OR : Returns true if at least one of the operands is true.

!      logical NOT : Returns the opposite boolean values of the operand.



Logical AND (&&) Operators


Program 1:


  #include<stdio.h>
  int main() {
    int a,b;
    a=10; // true
    b=20; // true
    printf("The value for AND operator:%d",a&&b);
  }


Output:


  The value for AND operator:1


Program 2:


  #include<stdio.h>
  int main() {
    int a,b;
    a=1; // true
    b=0; // false
    printf("The value for AND operator:%d",a&&b);
  }


Output:


  The value for AND operator:0


Logical OR (||) Operator





Program:


  #include<stdio.h>
  int main() {
    int a,b;
    a=10; // true
    b=0; // false
    printf("The value for OR operator:%d",a||b);
  }


Output:


  The value for OR operator:1


Logical NOT(!) Operator:


Program:


  #include<stdio.h>
  int main() {
    int a,b;
    a=1; // It gives opposite value 0
    b=0; // It gives opposite value 1
    printf("The value for NOT operator:%d",!a);
  }


Output:


  The value for NOT operator:0




More topic in C

Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send