Logical Operators

In this Tutorial, We learn About Logical Operators in C Programming

Logical Operators? The operators are used to perform logical operations on the given expressions those Operators are called Logical Operators. We have three operators like AND(&&) OR (||) and NOT(!) which are used to combine two or more conditions.



Here Are the Operators:- 


Example:-
#include<stdio.h>
void main()
{
    int c=0;
    //1 = true
    //0 = false

    // For AND (&&) Operator
    c = 1 && 1;
    printf("1 && 1 = %d\n",c);

    c = 1 && 0;
    printf("1 && 0 = %d\n",c);

    c = 0 && 1;
    printf("0 && 1 = %d\n",c);

    c = 0 && 0;
    printf("0 && 0 = %d\n",c);


    // For OR (||) Operator
    c = 1 || 1;
    printf("1 || 1 = %d\n",c);

    c = 1 || 0;
    printf("1 || 0 = %d\n",c);

    c = 0 || 1;
    printf("0 || 1 = %d\n",c);

    c = 0 || 0;
    printf("0 || 0 = %d\n",!c);

    // For NOT (!) Operator
    printf("For Not Operator\n");
    c = 1 ;
    printf("!c = %d\n",!c);

    c = 0;
    printf("!c = %d\n",!c);
 } 
OUTPUT
1 && 1 = 1
1 && 0 = 0
0 && 1 = 0
0 && 0 = 0
1 || 1 = 1
1 || 0 = 1
0 || 1 = 1
0 || 0 = 1
For Not Operator
!c = 0
!c = 1
  
Comment below if you have any queries related to the above tutorial for Logical Operators In C Programming.


Post a Comment

0 Comments